0

Please consider the following two files defined in the same package in eclipse.

PData.java

package com.abc.cast.q;


public class PData<F extends SF> {

SF.java

package com.abc.cast.q;
public interface SF{

  String getCName();

}

I am going through the code and noticed that the in PDData, F is extending SF, however, after looking SF.java, I came to know that it's an interface. So,in PData.java shouldn't it be F implements SF instead of F extends SF in this case?

The compiler doesn't complains

John
  • 1,210
  • 5
  • 23
  • 51
  • 1
    PData -> which is generics, introduced in java 5 different from inheritance. – Shriram Dec 31 '15 at 06:55
  • `Class`es implement `interface`, but a `interface` can `extend` other `interface`. Implementation (`implements`) means defining the behavior while `extends` means extending the features/operation which can be performed. – YoungHobbit Dec 31 '15 at 06:55
  • @YoungHobbit In my case, Class is extending interface, so the above code is wrong? But that is happening inside `< >` – John Dec 31 '15 at 06:56
  • `PData` this is not extending. this is called generics. Essentially it says, you are defining operations/behavior which are best suited to `F extends SF` types. – YoungHobbit Dec 31 '15 at 06:58
  • @YoungHobbit So, here I can say that a variable `F` is extending the class `SF` ? How would I interpret it? – John Dec 31 '15 at 06:59
  • I hope this will help in understanding the above [Bounded Type Parameters](https://docs.oracle.com/javase/tutorial/java/generics/bounded.html). – YoungHobbit Dec 31 '15 at 07:03

0 Answers0