简体   繁体   中英

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?

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> { ... }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM