Jump to content

Java "meta"-methods?

Featured Replies

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?

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.

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.