Coming from a C++ environment I got used to splitting up many of the functions that I needed into an funcs.h
file and then do #include "funcs.h"
and then adding the functions prototypes into the main .cpp file. Now I am starting to work with java (mainly with minecraft ModloeaderMp) and I already made a funcs.java
file where there are some premade functions (e.g some functions for file copying, giving stacks of items etc.). SInce I am already using the statement Public class mod_mine extends BaseModMp
, is there a way I can import the functions or do I can I just do another Public class mod_mine extends funcs
?
You don't #include
in Java, you import package.Class
. Since Java 6 (or was it 5?), you can also import static package.Class.staticMethodOfClass
, which would achieve some forms of what you're trying to do.
Also, as @duffymo noted, import
only saves you from systematically prefixing the imported class names with the package name, or the imported static method names with the package and class name. The actual #include
semantics doesn't exist in Java - at all.
That said, having a "funcs.java" file seems to me like you are starting to dip your toes into some anti-patterns... And you should stay away from these.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With