[BPSouther: Added code tags] [ April 03, 2008: Message edited by: Ben Souther ]
Ashok Kumar Babu
Ranch Hand
Joined: Jul 25, 2006
Posts: 129
posted
0
Hi Salman,
1.
GenericMethodSubtyping.someMethod1(l1); System.out.println(l.get(counter));// why i cannot call getSValue() method?
Let us check this condition first.
In the above declaration <A> does not represent Class A, so only the method getSValue is not available. <A> is just to indicate the generics - any instance, again the <A> before the void gives the explanation about it. To understand it clearly, the above statement is very similiar to the below.
So whats the way to say only Instance A.
See the missing before the void. this above declaration clearly says only instance of class A. With this declaration you can get getSValue() method.
2.
This is similar to Somemethod1 but while describing the generics it clearly says any class which is a sub class of Class A. So obviously objects in the list can be cast to Class B automatically, hence the getSValue method is available.
If anything is wrong in my explanation. please mark it out.