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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -