-1

What does the class name in < > signify?

public class classA extends classB <classC>

I know about inheritance, but exactly want to know what does < > means in classB <classC>

FYI : classA.java and classB.java are under the same folder of the project. classC.java is in different folder of the project.

jafarbtech
  • 6,339
  • 1
  • 33
  • 52
Urvika G
  • 191
  • 1
  • 15
  • You should have a look at the [oracle tutorial](https://docs.oracle.com/javase/tutorial/java/generics/index.html) on generics. – Paul Jan 11 '17 at 14:09
  • 1
    @MaňishYadav this is definitely not a question about multiple inheritance in java, but simply about generics in java. – Paul Jan 11 '17 at 14:10
  • @MaňishYadav I'd say "what does the class-name in <> signify?" is pretty obviously not the same as "why does my classA extend classB and classC?". And speaking from personal experience, getting people to agree with a close-vote on this sort of question is rather a social mechanism than anything else. – Paul Jan 11 '17 at 14:17
  • please explain what does the class in angular brackets signify :/ – Urvika G Jan 11 '17 at 14:21

1 Answers1

2

Here is a small excerpt from the definitions of the interfaces List and Iterator in

package java.util:

public interface List <E> {
    void add(E x);
    Iterator<E> iterator();
}

public interface Iterator<E> {
    E next();
    boolean hasNext();
}

This code should all be familiar, except for the stuff in angle brackets. Those are the declarations of the formal type parameters of the interfaces List and Iterator.

Type parameters can be used throughout the generic declaration, pretty much where you would use ordinary types (though there are some important restrictions; see the section The Fine Print.

In the introduction, we saw invocations of the generic type declaration List, such as List<Integer>. In the invocation (usually called a parameterized type), all occurrences of the formal type parameter (E in this case) are replaced by the actual type argument (in this case, Integer).

You might imagine that List<Integer> stands for a version of List where E has been uniformly replaced by Integer:

public interface IntegerList {
    void add(Integer x);
    Iterator<Integer> iterator();
}

This intuition can be helpful, but it's also misleading.

It is helpful, because the parameterized type List<Integer> does indeed have methods that look just like this expansion.

It is misleading, because the declaration of a generic is never actually expanded in this way. There aren't multiple copies of the code--not in source, not in binary, not on disk and not in memory. If you are a C++ programmer, you'll understand that this is very different than a C++ template.

A generic type declaration is compiled once and for all, and turned into a single class file, just like an ordinary class or interface declaration.

Maveňツ
  • 9,147
  • 14
  • 53
  • 94