Glorified classes in the Java language

前端 未结 13 1957
一生所求
一生所求 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: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 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.

提交回复
热议问题