简体   繁体   English

Oracle JDK 和 OpenJDK 中的字符串实现

[英]String implement in Oracle JDK and OpenJDK

I found the definition about String:我找到了关于 String 的定义:

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

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 ObjectGeneric是从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?创建 Open Jdk 文档时出现一些错误,或者我对 Java 中的 Generic 或 String 类型有误解?

See also:也可以看看:

The Java Language Specification says Java 语言规范

The class Object is a superclass (§8.1.4) of all other classes. Object类是所有其他类的超类(第 8.1.4 节)。

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所以你的 OpenJDK Java 7 链接中的String

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.这样就满足了 Oracle 链接中的 Javadoc。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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