T
T
thatmaniscool2017-06-05 21:38:54
Java
thatmaniscool, 2017-06-05 21:38:54

What is the difference between and in Java?

For example, I create a parent class from which everything will be inherited:

public class Parent <T extends Parent>{
  private T element;
  public Parent <T> set (T element){
    this.element = element;
    return this; // Возращаем копию класса.
  }
  public T get (){
    return element;
  }
}

Then I create several heirs.
public class Child extends Parent <Child>{}
public class Child2 extends Parent <Child>{}

So, what is the difference between the same code, only without parameter expansion
public class Parent <T> { // Без extends Parent
  private T element;
  public Parent <T> set (T element){
    this.element = element;
    return this; // Возращаем копию класса.
  }
  public T get (){
    return element;
  }
}

If everything works identically?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
ferasinka, 2017-06-05
@ferasinka

In the first case, all T will be turned into Parent, and in the second case into Object
javapapers.com/core-java/type-erasure

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question