default-package

Why shouldn't we use the (default)src package?

若如初见. 提交于 2019-11-28 08:51:41
问题 I recently started using Eclipse IDE and have read at a number of places that one shouldn't use the default(src) package and create new packages. I just wanted to know the reason behind this. 回答1: Using the default package may create namespace collisions. Imagine you're creating a library which contains a MyClass class. Someone uses your library in his project and also has a MyClass class in his default package. What should the compiler do? Package in Java is actually a namespace which fully

What is the default package in which my classes are put if I don't specify it?

百般思念 提交于 2019-11-26 22:58:14
Let's assume I have a file named Main.java with the following code: public class Main { public static void main(String[] args) { System.out.println("Hello world"); } } Is it put in a specific package, in (maybe?) an unnamed package? Thanks Lachlan Roche A class that is not in a named package is in an unnamed package . Thus the full class name is Main . Such classes cannot be used from a named package, except via reflection. The JLS says that: Unnamed packages are provided by the Java SE platform principally for convenience when developing small or temporary applications or when just beginning

What is the default package in which my classes are put if I don't specify it?

孤街浪徒 提交于 2019-11-26 08:27:23
问题 Let\'s assume I have a file named Main.java with the following code: public class Main { public static void main(String[] args) { System.out.println(\"Hello world\"); } } Is it put in a specific package, in (maybe?) an unnamed package? Thanks 回答1: A class that is not in a named package is in an unnamed package . Thus the full class name is Main . Such classes cannot be used from a named package, except via reflection. The JLS says that: Unnamed packages are provided by the Java SE platform

How to import a class from default package

狂风中的少年 提交于 2019-11-26 00:15:46
问题 Possible Duplicate: How to access java-classes in the default-package? I am using Eclipse 3.5 and I have created a project with some package structure along with the default package. I have one class in default package - Calculations.java and I want to make the use of that class in any of the package (for instance in com.company.calc ). When I try to make the use of the class which is in the default package, it\'s giving me a compiler error. It\'s not able to recognise the class in default

How to access java-classes in the default-package?

自作多情 提交于 2019-11-25 21:54:57
问题 I\'m working now together with others in a grails project. I have to write some Java-classes. But I need access to an searchable object created with groovy. It seems, that this object has to be placed in the default-package. My question is: Is there a way to access this object in the default-package from a Java-class in a named package? 回答1: You can’t use classes in the default package from a named package. ( Technically you can, as shown in Sharique Abdullah's answer through reflection API,