0

I have a jar called MyMathsJar.

I added it in the build path.

I can access to its content in the default package of my current project and it is working fine.

MyMaths m = new MyMaths();
System.out.println(m.addition(1, 3));

However, if I want to do the same thing in the package customerPack in my current project it is not working. I got this error :

MyMaths can not be resolved as a type.

Someone can explain me why please? Thank you.

Royce
  • 1,557
  • 5
  • 19
  • 44
  • 1
    Is the class you are attempting to use also in a default package? – Tom Hawtin - tackline Jan 24 '20 at 13:32
  • 3
    Don't use the default package. You can only ever access classes in the default package from code that is *also* in the default package. – Joachim Sauer Jan 24 '20 at 13:34
  • Yes it is in the default package. – Royce Jan 24 '20 at 13:35
  • @JoachimSauer thank you. Do you know the reason of this behavior? – Royce Jan 24 '20 at 13:36
  • 1
    @Royce: using the default package is prone to naming conflicts, so it's basically not supported for anything but the smallest sample programs. See [this question for details](https://stackoverflow.com/questions/7849421/is-the-use-of-javas-default-package-a-bad-practice). – Joachim Sauer Jan 24 '20 at 13:37
  • [How to access java-classes in the default-package?](https://stackoverflow.com/q/283816/85421) or [How to import a class from default package](https://stackoverflow.com/q/2193226/85421) – user85421 Jan 24 '20 at 13:39
  • It's a good reason ahah. Thank you. – Royce Jan 24 '20 at 13:39

0 Answers0