Jump to content

Recommended Posts

Posted

I am programming in java, and I am curious whether I could create a public static method to make public static methods. Is this feasible or impossible?

Posted

Freeman, what exactly do you need this for?

 

Also I'm not exactly sure what you mean...

 

Do you mean something along the lines of Preprocessor methods/actions such as are found in C where one can conditionally and even through certain functions define function code that will actually be compiled. I am not aware of anyway in the default java installation that you can do this sort of thing, and I haven't tried myself but there seem to be several java preprocessors that you can download which might be helpful.

 

Do you mean something along the lines of using different methods with the same method name depending on the situation? (ie function pointers, not method overloading). As far as I know Java doesnt support this, although you can have an interface which various classes implement that has a certain methods and then these implementations could have instance objects which can be passed into various methods, which can have the method run on them, executing different code depending on the class that that object belongs to (ie each class that implements that interface can implement it differently). This is what is done alot of the time with ActionListeners and so on in the GUI programming aspect of Java.

 

If you are simply looking to have different code loaded in at runtime depending on the situation (ie perhaps a plugin architecture) then you might want to look at the ClassLoader Class which allows precompiled class files to be loaded at runtime and used to create new instance objects.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.