This post originated from an RSS feed registered with Java Buzz
by Scott Delap.
Original Post: Java does Duck Typing
Feed Title: ClientJava.com
Feed URL: http://www.clientjava.com/archives/wireless_mobile.rdf
Feed Description: Client/Desktop Related Java Development
Java does Duck Typing As promised, this is the followup to Duck Typing helps automatically dispose SWT Images. Here, we will show how to implement Duck Types in Java ...
So, when working with SWT, you quickly learn that any time you want to set the display text of something, you look for a Text property to set. And in the case of setting display text, you would be right 100% of the time.
Unfortunately, this does not hold true for programs that want to manipulate SWT controls. There is no ITextField interface that is implemented by everything with a Text property, for example. And, as we mentioned last time, it would be silly for such a thing to exist, because there are so many naming conventions applied so consistently throughout SWT that every SWT class would be cluttered with interface implementations.
Consequently, it would be nice to be able to define an ITextField interface after the fact and apply it to any SWT class that happens to implement all of the methods specified by the ITextField interface.