Glorified classes in the Java language

前端 未结 13 1808
一生所求
一生所求 2021-01-29 20:32

Some classes in the standard Java API are treated slightly different from other classes. I\'m talking about those classes that couldn\'t be implemented without special support f

相关标签:
13条回答
  • 2021-01-29 21:06

    Java array as in int[].class

    0 讨论(0)
  • 2021-01-29 21:07
    1. Enum. You're not allowed to subclass it, but the compiler can.
    2. Many things under java.util.concurrent can be implemented without JVM support, but they would be a lot less efficient.
    0 讨论(0)
  • 2021-01-29 21:07

    Since the important classes were mentioned, I'll mention some interfaces:

    The Iterable interface (since 1.5) - it allows an object to participate in a foreach loop:

    Iterable<Foo> iterable = ...;
    for (Foo foo : iterable) {
    
    }
    

    The Serializable interface has a very special meaning, different from a standard interface. You can define methods that will be taken into account even though they are not defined in the interface (like readResolve()). The transient keyword is the language element that affects the behaviour of Serializable implementors.

    0 讨论(0)
  • 2021-01-29 21:10

    sun.misc.unsafe is the mother of all dirty, spirit-of-the-language-breaking hacks.

    0 讨论(0)
  • 2021-01-29 21:10

    java.lang.ClassLoader, though the actual dirty work is done by some unmentioned subclass (see 12.2.1 The Loading Process).

    0 讨论(0)
  • 2021-01-29 21:14
    1. Throwable, RuntimeException, Error AssertionError
    2. References WeakReference, SoftReference, PhantomReference
    3. Enum
    4. Annotation
    0 讨论(0)
提交回复
热议问题