Java class definition

I am trying to understand what this java class definition is.

abstract public class A<P extends B<?, ?>,Input,Output> { ... // class defined ... } 

C ++ programmer navigating in java

+4
source share
5 answers

This defines an abstract class named A with three type parameters:

  • P , which must be of type B (with any type arguments) or any type derived from it
  • Input any type
  • Output any type

Of interest is a parameter of the first type. In C ++, for a type-based template parameter, you can specify any type; in Java, you have the ability to restrict the type to which class and / or interfaces of this type should also be extended / implemented.

+3
source

A bit of "translation":

"abstract" means that this class can have abstract (~ = purely virtual) methods.

class A is a common (~ pattern) definition

P extends ... is an additional restriction on the general parameter, must be a subclass ...

P extends B <& le ;,> means that generic parameter # 1 is a subclass of another generic class

+1
source

This is a definition of an abstract class (obviously) with three typical parameters.

The first parameter P has a restriction on the fact that it must have type (or which extends) class / interface B, which has two common parameters (without restrictions on them) so that it can be like

 public class B<T1, T2> { } 

The second and third parameters, namely Input and Output, have no restrictions.

+1
source

Angle bracket designation for Java Generics .

-1
source

Well, to really understand this, you want to include more definitions, but B is a class with generics themselves, and A has three common references in it; it's a bit pathological, but pretty easy to get through.

-1
source

All Articles