cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.46k stars 158 forks source link

Default methods in interfaces are ignored #524

Closed PavelTurk closed 5 years ago

PavelTurk commented 5 years ago

I use JSweet on JSweet site. This is java code:

package org.jsweet;

import static def.dom.Globals.*;

interface Lala {

    public void doIt();

    default void defaultOne(){ 
        alert("Hi");
    }

    static void statOne() {
        alert("Hi2");
    }
}

And this is the generated typescript code:

/* Generated from Java with JSweet 2.2.0-SNAPSHOT - http://www.jsweet.org */
namespace org.jsweet {
    export interface Lala {
        doIt();

        defaultOne() : any;
    }

    export namespace Lala {

        export function statOne() {
            alert("Hi2");
        }
    }

}

As you see defaultOne implementation is ignored.

lgrignon commented 5 years ago

Hello, This is the intended behavior.

Please try

import static def.dom.Globals.*;

interface Lala {

    public void doIt();

    default void defaultOne(){
        alert("Hi");
    }

    static void statOne() {
        alert("Hi2");
    }
}

class Lolo implements Lala {
 public void coucou() {
     defaultOne();
 }
    public void doIt() {
    }
}

It will call defaultOne()