Q: Declaratively Implement a Java Interface, How?

Hi Again,
I want to be able to Declaratively Implement 'Response' in a JavaFX (very impressive stuff if I can do this!). Follow the example code below :)
Java Interface:
public interface Response {
   public String doResponse(String input);
}The JavaFX Class:
public class MyResponse extends Response {
  override public-init var doResponse: function (input:String):String; //doesn't work!
}JavaFX Declarative Implementation (the goal):
var responder:MyResponse {
    doResponse:  function (input:String):String {
        return "JavaFX Rocks!"
}So the above should allow whoever is creating "MyResponse" to implement the doResponse functionality of the class.
Alternatively, I can just have to do the following.....
public class MyResponse extends Response {
  public-init var doResponseImpl:function (input:String):String;
  public override function doResponse(input:String):String{
      return doResponseImpl(input);
}Either way works... but the alternative is not so nearly as clean :)
Thanks in advance...

I don't see a way to do this. You want to transform a function to a variable. Even if that's a variable holding a function, these are incompatible.
But you can just override the function in the class instantiation:
var responder = Response {
    override function doResponse(input: String): String {
        return "JavaFX Rocks!"
}

Similar Messages

  • Passing implementation of Java interfaces

    Hi
    I have a static function which I want to be supplied with a another class. Now the passed class needs to be an implementation of that class. How can I make sure?
    Thanks
    Saaransh

    an example:
    Lets say I have an interface :
    public interface foo
    //some methods
    Now thers a static function. Which I want should take in a parameter (an object) which has implemented the above interface.
    How do i do this?
    NOTE: I am making a framework API and thus the class making the object will not be known to me. It will be created by someone else and not me.
    Thanks

  • A java List that implements the Stream interface?

    Hello,
    I just took some time to start looking into the java-8 buzz about streams and lambdas.
    And have a couple of questions...
    The first thing that surprised me is that you cannot apply the streams operations,
    like .map(), .filter() directly on a java.util.List.
    First question:
    Is there a technical reason why the java.util.List interface was not extended with
    default-implementations of these streams operations? (I guess there is...?)
    Googling a bit, I see lots of examples of people coding along the pattern of:
        List<String> list = someExpression;
        List<String> anotherList = list.stream().map(x -> f(x)).collect(Collectors.toList());
    which becomes very clumsy, if you have a lot of these stream-operations in your code.
    Since .stream() and .collect() are completely irrelevant to what you want to express,
    you would rather like to say:
        List<String> list = someExpression;
        List<String> anotherList = list.map(x -> f(x));
    What I first did as a workaround, was to implement (see code below)
    a utility interface FList, and a utility class FArrayList (extending ArrayList with .map() and .filter()).
    (The "F" prefixes stand for "functional")
    Using these utilities, you now have two options to create less clumsy code:
        List<String> list = someExpression;
        List<String> anotherList = FList.map(list, x -> f(x));
        List<String> thirdList = FList.filter(list, somePredicate);
    or better:
        FList<String> list = new FArrayList<String>(someExpression);
        FList<String> anotherList = list.map(x -> someFunction(x));
        FList<String> thirdList = list.filter(somePredicate);
    My second question:
    What I would really like to do is to have FArrayList implement the
      java.util.stream.Stream interface, to fully support the java-8 functional model.
    Since that involves implementing some 40 different methods, I would just like to know,
    if you know somebody has already done this kind of work, and the code is
    available somewhere as a public jar-file or open-source?
        public interface FList<T> extends List<T> {
            public static <A, B> List<B> map(List<A> list, Function<A, B> f) {
                return list.stream().map(f).collect(Collectors.toList());
            public static <A> List<A> filter(List<A> list, Predicate<A> f) {
                return list.stream().filter(f).collect(Collectors.toList());
            default <R> FList<R> map(Function<T, R> f) {
                FList<R> result = new FArrayList<R>();
                for (T item : this) {
                    result.add(f.apply(item));
                return result;
            default FList<T> filter(Predicate<T> p) {
                FList<T> result = new FArrayList<T>();
                for (T item : this) {
                    if (p.test(item)) {
                        result.add(item);
                return result;
        public class FArrayList<T> extends ArrayList<T> implements List<T>, FList<T> {
            private static final long serialVersionUID = 1L;
            public FArrayList() {
                super();
            public FArrayList(List<T> list) {
                super();
                this.addAll(list);

    I believe SSH and telnet are used for interactive command line sessions, don't know how you want to use them in a program.

  • A Bean must implement the java.io.Serializable interface? What makes the di

    Hi, I have took an example from sun notes on JavaBeans (you can find the example here http://java.sun.com/developer/onlineTraining/Beans/beans02/page2.html). The code is like this.....
    import java.awt.*;
    import java.io.Serializable;
    public class SimpleBean extends Canvas
                     implements Serializable {
      private Color color = Color.green;
      //getter method
      public Color getColor() {
         return color;
      //setter method
      public void setColor(Color newColor) {
         color = newColor;
         repaint();
      //override paint method
      public void paint (Graphics g) {
         g.setColor(color);
         g.fillRect(20,5,20,30);
      //Constructor: sets inherited properties
      public SimpleBean() {
         setSize(60,40);
         setBackground(Color.red);
    }I didn't find any difference in executing the program by implementing the Serializable interface and without implementing. On choosing serialize component in the File Menu, I serialized the component after changing its color (property), and saved as .ser file. And created the .Jar file including .ser file. when I load the jar file and place the bean in the beanbox, it is showing the bean that is updated. This can be done by implemeting Serializable interface and without implementing Serializable interface also. And I have a statement that has been given in the notes provided by SUN. That is ' Bean must implement the Serializable interface. Objects that support this interface can save and restore their state from disk '. I couldnot come up with the summation of this statement.
    Anyone who has an idea... please give an explanation.
    Thank you.

    Maybe you should show us your coding how you saved your beans state.
    Are you serious that you save the special object? Or do you save the values of the object into a file and load those values into a new object?

  • We have a requirement to print the w2 forms for employees using java application, how can i implement this. Please give some suggestion.

    We have a requirement to print the w2 forms for employees using java application, how can i implement this. Please give some suggestion.

    Anyone any ideas to help please?

  • How resource files(.rc) are implemented in java

    I want to know how resource files are implemented in java. I am using a window98 as OS.
    Thank you
    Abu_ramla

    I wonder if this might help:
    ResourceBundle rbd = ResourceBundle.getBundle("Filename");
    to get a property out of the resourceBundle use:
    String varname = (String) prb.getObject("propName");
    As allways, check the API
    Hope this helps
    Elouiza

  • How to implement a java class

    dear friends
    i use forms6i server and oracle 9i server edition,under windows 2000 server
    i try to implement a java class for a bean area. i do the following :
    from the property palette i write the class name in implementaion class property . the class name is 'arc.class' and it is located in <oracle_home>/forms60/java
    but the fellowing error appears
    frm-13008 cannot find javabean with name 'arc.class'
    would any one help please

    Dear Grant Ronald
    thank you very much for helping me . now i undersatand how to implement a class. but i have another question ,and i wish you ccould help me .
    i try to import a java class, i do the following:
    From the program menue i choose Import Java Class
    but the following error appears
    (pde-uji001 faild to create JVM)
    by the way i use forms6i server and oracle 9i server under windows 2000 server
    thanks in advance
    tarek

  • EJB3 Stateful Sessionbean how to implement multi business interfaces?

    Hi All,
    I met up some issue, can't make the session bean implement 2 business interfaces? Please kindly throw me some light! thanks
    Business sessionbean
    @Stateful
    @ConversationScoped
    @Named
    @Local( { IWizard.class, IRegisterWizard.class })
    public class RegisterWizard extends WizardBean {
    @Local
    public interface IWizard extends Serializable {
            public String back();
            public boolean hasBack();
            public boolean hasNext();
            public String next();
            public String abort();
    @Local
    public interface IRegisterWizard{
            public String submit();
    }error message of glassfish3 below:
    Caused by: java.lang.IllegalArgumentException: Not enough type information to resolve ejb for  ejb name class wizard.RegisterWizard
            at org.glassfish.weld.services.EjbServicesImpl.resolveEjb(EjbServicesImpl.java:121)
            at org.jboss.weld.bean.SessionBean.createReference(SessionBean.java:422)
            at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.<init>(EnterpriseBeanProxyMethodHandler.java:76)
            at org.jboss.weld.bean.SessionBean.create(SessionBean.java:298)
            ... 53 more

    There does appear to be a bug in the handling of the bean with multiple business interfaces. I filed an issue for it :
    https://glassfish.dev.java.net/issues/show_bug.cgi?id=11826. The inheritance is a separate issue. Are you getting the same error or a different one after applying @LocalBean.

  • How to name implementation of an interface

    Hi there
    is there any standard for naming concrete implementation of interfaces?
    So if I have an interface
    A
    in package "interfaces"
    is it sensful to call the concrete implementation of the interface interfaces.A A, too?
    class A implements interfaces.A{
    }? Or should it be called ConcreteA, or or or....?
    Thx for your tips.
    Sincerely
    Karlheinz Toni

    JebeDiAH heres a very interesting reading.
    Class and Interface Names
    Class names are always nouns, not verbs. Avoid making a noun out of a verb, example DividerClass. If you are having difficulty naming a class then perhaps it is a bad class.
    Interface names should always be an adjective (wherever possible) describing the enforced behaviors of the class (noun). Preferably, said adjective should end in "able" following an emerging preference in Java. i.e. Clonable, Versionable, Taggable, etc.
    Class, and interface names begin with an uppercase letter, and shoule not be pluralized unless it is a collection class (see below).
        Acceptable:
            class FoodItem
            interface Digestable
        UnAcceptable:
            class fooditem
            class Crackers
            interface Eat
    Naming collection classes (in the generic sense of collection) can be tricky with respect to pluralization. In general each collection should be identified as a plural item, but not redundantly so. If you are a collection type as part of the class name (List, Map, etc.) it is not necessary to use the plural form in the class name. If you are not using the collection type in the name it is necessary to pluralize the name. If you are extending one of the java colletction class (Map, HashMap, List, ArrayList, Collection, etc.) it is good practice to use the name of the collection type in the class name.    
        Acceptable:
            class FoodItems extends Object
            class FoodItemList extends ArrayList
            class FoodItemMap extends HashMap
        UnAcceptable:
            class FoodItem extends ArrayList
            class FoodItemsList extends ArrayList
    Class names should be descriptive in nature without implying implementation. The internal implementation of an object should be encapsulated and not visible outside the object. Since implementation can change, to imply implementation in the name forces the class name and all references to it to change or else the code can become misleading.
        Acceptable:
            AbstractManagedPanel
            LayeredPanel
        UnAcceptable:
            PanelLayerArray
    When using multiple words in a class name, the words should be concatenated with no separating characters between them. The first letter of each word should be capitalized.
        Acceptable:
            InverntoryItem
        UnAcceptable:
            Inverntory_item
            Inventoryitem
    Other than prefixes, no abbreviations should be used unless it is a well known abbreviation.
        Acceptable:
            CD=Compact Disc
            US=United States
        UnAcceptable:
            Cust=Customer
            DLR=Dealer
    I found it at http://www.iwombat.com/standards/JavaStyleGuide.html

  • First ever post..how does java interface an appl

    Here is my problem...
    I am trying to write a Java application that will allow me to track mouse movements, clicks, obtain urls, and other browser tracking data. I have searched forums enlessly and cant find the answer to my question. This is my first ever post dont let me down : )
    1. How do I get a java application to retrieve, get or load an interface to ie or netscape that I can use their functions and retrieve information.
    I need this for a school project and although there other ways maybe more suited, applet, script or whatever, this is my task. I have searched and cant find what the mechanics are for how java is to interface and use an application.
    thanks...

    I was excited to get a reponse...
    I understand an applet runs in a browser and application runs independently. But say I want my java application program to interact with an application such as a browser. I want to grab data from it, such as mouse clicks and urls.
    What I havent seen is how to do this. I am told that in C programing a dll would be loaded and imported functions could be called from within the C program, is there anything like this in java. How do I use an the ie or navigator API with Java?
    thanks...

  • How advantages of "Call By Reference" can be implemented using Java

    As I know that java doesnot support "Call By Reference" as C++
    does.
    I want to know that how advantages of Call by Reference can be
    implemented using Java.

    There is some misunderstanding here. Method arguments in Java are passed by value. However, if you pass a reference (to an object) by value, you can still modify the object that the (copy of the) reference points to.
    public void method1() {
      StringBuffer buf = new StringBuffer();
      // Here, method2 cannot change the value of the variable buf,
      // but it can modify the object that buf points to.
      method2(buf);
    public void method2(StringBuffer sb) {
      // You can modify the StringBuffer.
      sb.append("hello");
      // But this is useless, it will not change the variable buf
      // in the calling method.
      sb = new StringBuffer();
    }Jesper

  • How to implement a java application in Portal

    Hello,
    I was asked if it is possible to implement a java (not a web application / not java web dynpro) to implement into the portal. Is this possible with something like the java web start? Is someone using something like that in the real world?
    Thanks a lot,
      Vanessa

    Hi Vanessa.
    Yes, it is possible to integrate Java applets into portal. Have a look at XML Form Buider or SAP Management console (http://portalhost.domain:5xx13).
    Best regards,
    Aliaksandr Zhukau

  • Java Interface Question.

    There are classes in the Java SDK, such as the Interface:
    org.w3c.dom.Document
    that have factory methods in them that carry out actual operations.
    But how can this be possible, because when I program an interface:
    public interface test {
    public void setString(String s);
    It will only compile thus, with no implementation on the method signatures?
    How do Java interfaces with factory methods to this?
    org.w3c.dom.Node is another one. Where does the functionality/method implementation
    come from?

    public interface MyInterface {
         public void method1();
    class MyImplementation implements MyInterface {
         public void method1(){
    public class MyFactory {
         public static MyInterface createMyInterface(){
              return new MyImplementation();
    public class Test{
               public static void main(String args[]){
                      MyInterface x=MyFactory.createMyInterface();
                      x..method1();
    }Now can you understand this? Assume all These classes are separate classes. This is not a problem with inner classes. Before make a reply, try to understand it or post a reply as saying it is not clear rather than posting this kind of post.

  • Exception Declaration and the Public Interface

    What is the connection between a method , exception declaration ( throw ) and public interface. Does every method has an implicit public interface ?? Is list of thrown exceptions, part of a method&rsquo;s public interface ?

    sagararya wrote:
    So, how do we know that some method throws an exception that we have to catch?Via the throws clause.
    [http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html]
    Just as a method must specify what type and how many arguments it accepts and
    what is returned, the exceptions that a method can throw must be declared (unless the
    exceptions are subclasses of RuntimeException). Also those that are subclasses of Error need not be declared.
    The list of thrown exceptions
    is part of a method&#8217;s public interface.Ah, now I see what you mean. Where did you read that? I don't recall having ever heard the phrase "public interface" used like that.
    The above paragraph is from the book, Osborne_Java, written by James Kussow.. Ok.
    Can anybody explain me the 4th line in the above paragraph, starting from "The list of thrown exceptions ... "
    The list of thrown exceptions is part of a method&#8217;s public interface.
    The throws keyword is used as follows to list the exceptions that a method can throw:What part do you not understand? Read the tutorial I linked, and if something is still not clear, ask your specific question.
    Personally I think the phrase "public interface" is misleading here. If that's what you're hung up on, don't be. It doesn't mean "public" in the sense of Java's "public" access modifier. It just means the list of exceptions is part of what callers of the method know about it.
    EDIT: Oops. Too late.
    Edited by: jverd on Jun 25, 2008 8:31 AM

  • Implementation of java.lang.Serializable writeObject()

    Hi,
    Who (what class) provides the implementation for writeObject() and readObject() for java.lang.Serializable Interface?
    And in general for these Interfaced (Somewhere called Marker Interface), how does the implementation applies?
    How do they distinguished from other Interfaces?

    >
    Who (what class) provides the implementation forwriteObject() and readObject() for
    java.lang.Serializable Interface?
    And in general for these Interfaces (Somewhere called
    Marker Interface), how does the implementation
    applies?
    How do they distinguish from other Interfaces?
    The Serializable interface is a marker interface because it doesn't require the programmer to implement any methods whasoever, so the syntax:
    class MyClass implements Serializable { }
    is perfectly legal.
    This just tells the compiler that al objects of type MyClass will be serializable. No class provides the implementations for readObject() and writeObject(), you'll have to do that yourself. Or, more exactly, it is (strongly) recommended to do that, if you want to control what is and isn't serialized (you may have sensitive members in your class, that you don't want to be serialized!)
    Ok, these 2 methods are defined somewhere (I don't have the Java Serialization specification with me right now :( ), you have to implement them to give you better control of what's going on. Inside these methods you'l want to use the readObject() and writeObject() methods of other types).
    I'll come back later with a full example.
    Yuo may want ot check out the Java Serialization Specification (available for download on the Sun website)

Maybe you are looking for