UPDATE:
Thanks to @RC for solving this for me:
public class DataHandler<I, T extends IDataStore<I>> implements IHollywood<T, I>
From his comment I learned how to fix the ActorImpl:
public class ActorImpl extends DataHandler <Long, Actor> implements IHollywood
Solved.
I am currently trying to learn Java and am having some difficulty with generics. I am stuck on how to correctly implement a generic interface using two different type parameters and then extend this new implementation by two other interfaces that extend the original interface.
This is what I am trying to accomplish:
public interface IDataStore<ID> extends Serializable
public interface IHollywood<T extends IDataStore <ID>, ID>
{
List<T> retrieve() throws Exception;
void sotre(T t) throws Exception;
}
public interface IActor extends IHollywood <Actor, Long>
public interface IDirector extends IHollywood <Director, Long>
public class DataHandler<T> implements IHollywood <IDataStore<T>, T>
public class ActorImpl implements IActor extends DataHandler
public class DirectorImpl implements IDirector extends DataHandler
I have two points of confusion:
What is the correct signature for DataHandler? Currently I am using public class DataHandler<T> implements IHollywood <IDataStore<T>, T> and I know I am passing T as two parameters wrongly but can’t figure out the right way
What is the correct way for ActorImpl and DirectorImpl to implement IHollywood and extend DataHandler declaration?
Edit/Update:
I'll try to give more details:
// 1- support serialization
// provide interface to create/store/query persisted data
public interface IDataStore<ID> extends Serializable
public interface IHollywood<T extends IDataStore <ID>, ID>
// 2- provide an interface for Actor specific methods
public class Actor{}...
public interface IActor extends IHollywood <Actor, Long>
// Implement IActor
public class ActorImpl implements IActor
// 3- provide an interface for Director specific methods
public class Director{}...
public interface IDirector extends IHollywood <Director, Long>
// 4- Implement Director
public class DirectorImpl implements IDirector
// 5- Instead of CRUD, I’ll use a better name
// Implement retrieve()/store()/find methods
public class DataHandler <T> implements IHollywood <IDataStore<T>, T>
This way, I can use DataHandler to implement retrieve()/store()/find() methods of IHollywood
I can derive ActorImpl and DirectorImpl from DataHandler to use its retrieve()/store()/find() methods
I know IActor and IDirector extend IHollywood but I do not want to duplicate implementation of retrieve()/store()/find() methods of IHollywood. I want the DataHandler to implement them and ActorImpl and DirectorImpl to just inherit and use them, besides providing their own specific methods in their own implementation.
I hope this clarifies a bit what I need help with.
Thanks to @RC for solving this for me:
public class DataHander<I, T extends IDataStore<I>> implements IHollywood<T, I>
From his comment I learned how to fix the ActorImpl:
public class ActorImpl extends DataHander <Long, Actor> implements IHollywood
Solved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With