Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface implementation syntax sugar with SWT ?

 
Senhor Ignoradoo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i have this snippet from SWT:



I understad all the code, except:



Looks like it´s implementing an interface ? Can somebody provide me an explanation or a link to some book that explains that ?

Thanks in advance.
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's creating a Listener instance and using an in-line declaration to override the "handleEvent" method, that's what seems to contain the logic for the toggle button -> radio button behavioural change mentions in the comment header.

J.
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's an anonymous inner class example. That's probably the only place you will apply "new" keyword to the name of an interface. That's how you create an object of a class which implements an interface. The class implementing the interface becomes anonymous here as you have a reference of type interface to an object of that class. Nested classes from SUN tutorials gives you a brief explanation.
 
Senhor Ignoradoo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I got now :-).
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15439
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sr Ignorado, please check your private messages for an administrative matter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic