简体   繁体   中英

String implement in Oracle JDK and OpenJDK

I found the definition about String:

String in Oracle Jdk extends Object but Open Jdk doesn't

And when i create an example code with generic type as:

    public void testMethod(Map<String,?> map)
    Map<String,String> tmpMap = new HashMap<String, String>();
    tmpMap.put("Test", "Test");
    testMethod(tmpMap);

it compile and run without any errors on two platforms.

? in Generic is any types which extends from Object

So my question is:

  • There are some mistakes when creating Open Jdk document or i am misunderstanding about Generic or String type in Java?

See also:

The Java Language Specification says

The class Object is a superclass (§8.1.4) of all other classes.

So a class declared as

public class SomeType 

is actually equivalent to

public class SomeType extends Object 

So the String class from your OpenJDK Java 7 link

public final class String implements java.io.Serializable, Comparable<String>, CharSequence

is actually equivalent to

public final class String extends Object implements java.io.Serializable, Comparable<String>, CharSequence

So that satisfies the Javadoc in the Oracle link.

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