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 package. Where is the problem?
Calculations.java - source code
public class Calculations { native public int Calculate(int contextId); native public double GetProgress(int contextId); static { System.loadLibrary("Calc"); } }
I can't put my class in any other package. This class has some native methods which are implemented in Delphi. If I put that class in any of the folders, I will have to make changes to that DLL which I want to avoid (really - I can not). That's why I put my class in the default package.
To import the java package into a class, we need to use the java import keyword which is used to access the package and its classes into the java program. Use import to access built-in and user-defined packages into your java source file to refer to a class in another package by directly using its name.
In every java class, java. lang is imported by default.
lang Package. Java compiler imports java. lang package internally by default.
A class with default access has no modifier preceding it in the declaration. Default access is simple in that only the code within the same package can access code with default access. In other words, a class with default access can be seen only by classes within the same package.
From the Java language spec:
It is a compile time error to import a type from the unnamed package.
You'll have to access the class via reflection or some other indirect method.
Classes in the default package cannot be imported by classes in packages. This is why you should not use the default package.
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