0

I am working on project.

I need to Access parent class methods of the parameter of a generic class.

The structure is like:

public interface XYZ{
  methodToAccess1();
}
 public interface PQR{
  methodToAccess2();
}

An instance through which I have to access this method:

ABC<Tparams extends XYZ, Tresults extends PQR> obj;

The XYZ and PQR interface are implemented by various other class and these methodToAccess() are implemented in these classes. So my aim is to access these implemented methods, through obj. So is there anyway i can access methodToAccess() from obj object??

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
user2696258
  • 1,159
  • 2
  • 14
  • 26
  • Your question doesn't make much sense. Suppose ABC is List. You would thus have a List, and are asking if, when having an instance of List, you can call the method XYZ.methodToAccess1(). If the list is empty, you can't. If the list has 10 elements, you can call it on those 10 elements. But that's only an example: a, instance of ABC doesn't necessarily allow accessing an instance of XYZ. – JB Nizet Aug 12 '15 at 05:56
  • its actually like: List> obj. and ABC is user-defined class: ABC. Now I want : obj.get(0).something.methodToAccess(), of XYZ, assuming methodToAccess() is implemented properly in all the classes which implement XYZ. I know its confusing. But im asking can we do it or not? – user2696258 Aug 12 '15 at 06:19
  • No problem if ABC has a non-null public field named `something` of type TParams. – JB Nizet Aug 12 '15 at 06:21
  • thanku.. one more thing, if I have TParams params; in ABC class. Can I do params = (TParams) getParameter(); and getParameter() returns object of a class : MNQ ??. basically is this type of cast allowed? – user2696258 Aug 12 '15 at 07:20
  • because for populating that something I need to do above thing, otherwise its NULL – user2696258 Aug 12 '15 at 07:32

0 Answers0