java - Why use method local abstract inner classes -


one of legal modifiers can use method local inner classes abstract.

for example:

public class outer {     public void method(){         abstract class inner{         }     } } 

is there situation use this?

you have know scjp exam.

the invalid assumptions in original question. legal/valid java doesn't mean need use, or need know.

i can't recall scjp contains odd corner case questions.

i tried come case have used abstract class declared in method, looks odd, , reeks of bad design. here's code example came (still bad code design imho)

public class batchexecutor {      public static enum resultnotification {         jms,         mail     };      public runnable createrunnable(resultnotification type) {         abstract class prototype implements runnable {             public void run() {                 performbusinesslogic();                 publishresult();             }              abstract void publishresult();         }          switch (type) {             case jms: {                 return new prototype() {                     void publishresult() {                         //post result jms                     }                 };             }             case mail: {                 return new prototype() {                     void publishresult() {                         //post result mail                     }                 };             }         }         return null;     }      private void performbusinesslogic() {         //some business logic     }  } 

Comments