如何在 Google Web 工具包 (GWT) 中从 JSNI 调用接口(实例化)
How to call interface(instantiate) from JSNI in Google Web toolkit(GWT)
我有一个实现接口的 class,我需要在下面的代码 GWT.see 中从 JSNI 调用该方法,
接口:
public interface HeaderFormatter {
String format(String value);
}
class:
public GWTGrouping implements HeaderFormatter {
public String format(String value){
return "<span><i class='fa fa-stop'></i></span>";
}
public void performGrouping(){
if(isgroup){
grouping();
}
}
public static native void grouping() /*-{
//dont want to pass whole class to this method (this)
//Need to access format(String value) Method which will return some logic
//How to access that method here by passing interface not whole class
}-*/;
}
你可以这样做:
public static native void grouping(HeaderFormatter hf) /*-{
var value = // some String
var result = hf.@path.to.interface.HeaderFormatter::format(Ljava/lang/String)(value);
}-*/;
我有一个实现接口的 class,我需要在下面的代码 GWT.see 中从 JSNI 调用该方法,
接口:
public interface HeaderFormatter {
String format(String value);
}
class:
public GWTGrouping implements HeaderFormatter {
public String format(String value){
return "<span><i class='fa fa-stop'></i></span>";
}
public void performGrouping(){
if(isgroup){
grouping();
}
}
public static native void grouping() /*-{
//dont want to pass whole class to this method (this)
//Need to access format(String value) Method which will return some logic
//How to access that method here by passing interface not whole class
}-*/;
}
你可以这样做:
public static native void grouping(HeaderFormatter hf) /*-{
var value = // some String
var result = hf.@path.to.interface.HeaderFormatter::format(Ljava/lang/String)(value);
}-*/;