• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about abstract local classes

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can think of one reasonable usage of abstract local class: as workaround for "anonymous class can't inherit more than 1 classes/interfaces" limitation

but still, why does this language construct necessary?
any ideas?
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but you can't instantiate an abstract class...
 
Aaron Anders
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Ernest:
but you can't instantiate an abstract class...


well, the code above compiles successfully... it actually instantiates an anonymoous class.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aaron,
I think you are right about one of the use of the local abstract class.
Here you are creating an annonymous class at line 2 by extending abstract class LocalDummy. If you just add an abstract method in the definition of LocalDummy at line 1, this code will fail to compile.
I am not sure if that was your doubt.
Thanks,
Ambapali

class C1 { /* ... */ }
interface I1 { /* ... */ }
interface I2 { /* ... */ }
class SampleUsage{ void memberFun() {
abstract class LocalDummy extends C1 implements I1, I2 {
// ... whatever ... //line 1
}
LocalDummy anonymous = new LocalDummy() { /* ... */ }; }} //line 2
 
reply
    Bookmark Topic Watch Topic
  • New Topic