Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you #include files in java?

Tags:

java

include

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?

like image 817
MrJackV Avatar asked Oct 12 '11 09:10

MrJackV


1 Answers

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.

like image 54
Romain Avatar answered Sep 29 '22 19:09

Romain