1

I'm trying to write a module of code which can be used with Javascript for the client side browser and Kotlin for a Java desktop application and Android app.

The main logic manipulates a bitmap/png file.

Is there a way which I can write an interface to be used and have different implementations of the interface for JS and Kotlin?

For example, write a wrapper class for an image (load from image, set pixels, get pixels) in Java (using BufferedImage) and JS (using Canvas)?

I'm new here so if anything doesn't make sense or needs more clarification, please let me know!

1

1 Answer 1

1

Yes, it's certainly possible to do that. This answer is a generic Java and JavaScript answer; there may also be a Kotlin-specific approach, see the link in zsmb13's comment. But the generic Java and JavaScript approach would be:

  1. Write your interface around BufferedImage in Java
  2. Write your interface around canvas in JavaScript
  3. Write your manipulation code using that interface in JavaScript
  4. On the browser, your manipulation code would run directly on the browser's JavaScript engine
  5. In the Java app, you'd run your JavaScript code using javax.script to run it in Nashorn (or Rhino on older Java environments).

Whether it's the best solution to your problem is something only you can decide, but yes, you can do it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.