美文网首页
Java collections. Why no Primiti

Java collections. Why no Primiti

作者: sherrysack | 来源:发表于2018-05-17 11:04 被阅读0次

    The problem with primitive types (at least until Java 5) is that they didn't extend from the base Object class. All of the collections need to specify a class for all the methods they are using - and they specify Object, since Object is the base of all the classes.

    As of Java 5, you will find that Java will implicitly switch between a primitive and it's corresponding wrapper class when you need it. This means you can add an int, or a double, etc. to a Collection. The VM will automatically wrap the primitive in a wrapper class for you and place the wrapper in the Collection.

    相关文章

      网友评论

          本文标题:Java collections. Why no Primiti

          本文链接:https://www.haomeiwen.com/subject/obfbdftx.html