klampo
klampo

Reputation: 135

What is the meaning of this class?

class Drive <String, Integer> {

}

What is the meaning of this class with generic return type as string and integer?

Can we make a class as such class definition?

Upvotes: 2

Views: 76

Answers (1)

assylias
assylias

Reputation: 328608

It is a class with two generic types - note that String and Integer in this case don't have their usual meaning, they are the names of the generic types, hiding the java.lang.String.

For example, this would not compile, because String in your class is not a usual string:

static class Drive <String, Integer> {
  private void m() {
    String s = ""; //incompatible types
  }
}

Bottom line, your life would be easier if you stuck to the convention of using single letters, for example:

class Drive <T, U> { ... }

Upvotes: 6

Related Questions