Re: Simple question about Java Methods
Danger_Duck <ganggang3ster@gmail.com> writes:
org.eclipse.swt.widgets.Combo.Combo [...]
Based on the selection, I want to create a different function.
I don't know org.eclipse, but you can create function objects
interface Function { public double valueAt( final double x ); }
class Sin implements Function
{ public double valueAt( final double x )
{ return java.lang.Math.sin( x ); }}
....
final Function sin = new Sin();
....
And then you can store the object ?sin? in the combo box
field, so that it is returned upon selection - if org.eclipse
supports this.
So there will be no need to ?create? anything, the function
object can be used directly as sent by the field, possibly
after a downcast from ?Object? to ?Function?.
~~
It is a big shame than Java SE does not define common interfaces
such as ?Function<S,T>?. This would increase interoperability
between source code from different sources as they could then
all share these interfaces. Nowadays, unfortunately, everyone
is still forced to define his own interface. For example,
http://www.purl.org/stefan_ram/html/ram.jar/de/dclj/ram/Function.html