google / j2cl

Java to Closure JavaScript transpiler
Apache License 2.0
1.22k stars 143 forks source link

predicate is not usable by but exposed to JavaScript. #210

Closed wowoName closed 10 months ago

wowoName commented 10 months ago

Type of parameter 'predicate' in 'RowResult[] DataTable.Select(Predicate predicate)' is not usable by but exposed to JavaScript.

public RowResult[] Select(Predicate predicate){ return rows.stream().filter(predicate).toArray(RowResult[]::new); }

rluble commented 10 months ago

That seems correct, the class java.util.Predicate is opaque to JavaScript (it is not marked @JsType nor has any @JsMethod)

I assume the the class DataTable is either marked @JsType or its method Select(Predicate) is declared as @JsMethod and that is why the warning is emitted. The method is declared to be callable directly from user written JavaScript code but takes a parameter that is opaque.

Difficult to tell with certainty since it is an incomplete snippet.

rluble commented 10 months ago

Closing the issue as WAI.

wowoName commented 10 months ago

thanks! This is my code: @JsType(isNative = true,namespace = JsPackage.GLOBAL) public class DataTable {

@JsMethod
public native  RowResult[] Select(Predicate<RowResult> predicate);

}。 I am trying to rewrite the DataTable class in js as an overridden java class. So the above problem occurred when I was packing. (When I typed the complete java code, I found that the size of the package was too large, almost 90M, so I rewrote some java classes in js to reduce the size of the package). If the current issue does not work out well, is there any way to reduce the package size (currently my configured compilationLevel: SIMPLE_OPTIMIZATIONS). thanks~