Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add support for class extension and interface in Java generator

See original GitHub issue

hi i would like to have the generated java class to extend or implement an interface. the generated class should look something like

public class MyClassifier implements com.acme.domain.MyInterface {
   public double[] getScore(double[] input) {

notice the need to remove the static modifier from the method getScore

the need is to have multiple models running via calling the interface.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

izeigermancommented, Jul 30, 2020

Hey @yarix thank you so much for reporting this as well as for you PR!

Perhaps I’m missing the point but it seems like this functionality is somewhat redundant in m2cgen and goes beyond what this library is suppose to do.

I’d argue that the manual modification of the generated code is not required either. In OOP world the problem of adapting one interface to another has been long solved by the Adapter (aka Wrapper) design patter.

For example in the application code it’s fairly easy to do the following:

class MyClassifierAdapter implements com.acme.domain.MyInterface {
   public double[] getScore(double[] input) {
      return MyClassifier.score(input);

This entity has to be created once and can never be revisited even if the model changes.

Alternatively this can be solved in an even more straightforward way if the MyInterface is a SAM (Single Abstract Method) interface and you’re using Java >=8:

MyInterface classifier1 = (input) -> MyClassifier1.score(input);
MyInterface classifier2 = (input) -> MyClassifier2.score(input);

This is even less verbose.

Given the last example, I don’t see much value in bringing interface support to m2cgen.

Please let us know what you think!

StrikerRUScommented, Apr 12, 2021

I’m going to close this issue according to the following statements:

m2cgen tries to generate as minimal as possible working code that can be run from outer piece of code.

Given the last example, I don’t see much value in bringing interface support to m2cgen.

Thanks a lot for using m2cgen and for bringing this discussion up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generator (Oracle Fusion Middleware Java API Reference for ...
The interface implemented by all Class Generators. A Generator is responsible for generating custom code for specific class types. The Generator is expected ......
Read more >
Extending Classes And Interfaces - NativeScript Docs
Learn how NativeScript supports the native Android development scenarios which involve inheriting and extending existing classes or implementing interfaces.
Read more >
Java 8 add extension/default method to class - Stack Overflow
Now I have been reading about Java 8's default methods, but as far as I can see, I can only add these to...
Read more >
Add extension to force generated classes to implement ...
Fixed for 0.3.7. There is now a new extension property "javaInterfaces" that takes an array of strings, where each string is the fully...
Read more >
JavaGenerator (PegaRULES Java Engine v7.4.0 - PUBLIC)
The JavaGenerator interface identifies the code fragments required to specify how a defining Rule- instance is to be implemented.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found