-2

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:

6
  • 3
    Wait, what's the issue? All class types extend Object implicitly. Commented Mar 28, 2014 at 3:13
  • @SotiriosDelimanolis String in Open Jdk does not extends Object class :-) Commented Mar 28, 2014 at 3:14
  • 4
    All class types extend Object implicitly. Commented Mar 28, 2014 at 3:15
  • @SotiriosDelimanolis Sorry, but in Open Jdk document, String does not extends Object type :-) Commented Mar 28, 2014 at 3:17
  • 3
    @RongNguyen: you need to fetch a dictionary and look for the meaning of the word "implicitly". Commented Mar 28, 2014 at 3:18

1 Answer 1

6

The Java Language Specification says

The classObject 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.