Giter Club home page Giter Club logo

Comments (3)

rluble avatar rluble commented on September 1, 2024

This is normally achieved by what we call super-sourcing, where you pass different versions of the source when building for different targets. You can look at the way j2cl provides different implementation of some of the JRE classes for wasm (search for super-wasm).

In general, native types should only be present for web pathway.

from j2cl.

gkdn avatar gkdn commented on September 1, 2024

Maybe we could add a new annotation to signal that the method's implementation is meant for vanilla Java only, but not for JavaScript environments

There is GwtIncompatible which is shortcut for super-sourcing to enable reuse but here it seems like you want the method to be available in all environments in someway (i.e. "native" in JavaScript and implemented behavior in Java for JVM).

For something like that, you can delegate the static method interface to a class (e.g. Platform.java) where you have different version for specific platforms like rluble described. Or you can put factory method to another class similar to Guava where you can have different implementation for the factory itself (Dictionaries.newDict). These approaches make it clear to the user what is going on without adding another magical behavior hidden by annotations.

from j2cl.

kohlschuetter avatar kohlschuetter commented on September 1, 2024

The "super sourcing" approach is something that doesn't work well for libraries, because you would have to provide different dependencies for each of your environment targets, which is a big code smell, in my opinion.

See commit a5b37d6 for a fix in my fork.

However, I understand that this change may not be a focus for mainline j2cl, so I'm only adding this reference for posterity.

from j2cl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.