mercredi 2 décembre 2015

Run Java application with minimal code (hiding the main-method) [duplicate]

This question already has an answer here:

I'm writing a small library that I want to use when teaching Java to people. I'm trying to avoid static methods in the start because they just cause confusion. More specifically I would like to avoid having to instantiate a class to use non-static methods and fields.

An example of a Java program using the library would hopefully be something like this:

public class Test extends Application {
    @Override
    public void run() {
        System.out.println("Hello.");
    }
}

I have played around with reflection to instantiate the class, but Eclipse won't even let me define a run configuration even though there is a main method in the library.

The less amount of setup required (IDE settings, boilerplate code, etc...) the better. Is it possible to define a class like this, or something similar, and run it in an IDE? Any help or suggestions are appreciated.





Aucun commentaire:

Enregistrer un commentaire