Why use method local abstract inner classes

后端 未结 10 1762
名媛妹妹
名媛妹妹 2021-02-05 04:45

One of the legal modifiers you can use with method local inner classes is abstract.

For example:

public class Outer {
    public void method(){
        a         


        
10条回答
  •  死守一世寂寞
    2021-02-05 05:34

    Is there any situation where you would actually use this?

    1. Let S1 denote all situations in which you need an abstract class.

    2. Let S2 denote all situations in which you need a local class.

    3. The answer to your question can be found by examining S1 ∩ S2

    Related questions:

    • What benefit do method-local inner classes provide in Java?
    • Use of Java [Interfaces / Abstract classes]

    Clarification: My point is that the two features (abstract classes and local classes) are two completely orthogonal features of the language. Understanding when each feature is useful is the key to understanding when they are both useful at the same time.

提交回复
热议问题