How to extends Abstract Inner Class in java -


i confused if

abstract class a{method();method2();} 

and other class b have inner class c

class b{abstract class c{method(){//body}}} 

and question how extends class c b/c abstract class must extends else unused class.

first, let's make simpler - has nothing android directly, , don't need a class @ all. here's want:

class outer {     abstract class inner {     } }  class child extends outer.inner { } 

that doesn't compile, because when create instance of child need provide instance of outer inner constructor:

test.java:6: error: enclosing instance contains outer.inner required class child extends outer.inner { ^ 1 error 

there 2 options can fix this:

  • if don't need refer implicit instance of outer inner, make inner static nested class instead:

    static abstract class inner { } 
  • you change child accept reference instance of outer, , use that call inner constructor, uses surprising syntax, works:

    child(outer outer) {     // calls inner constructor, providing     // outer containing instance     outer.super(); } 

note these alternatives - should pick 1 want based on whether or not inner class needs inner class.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -