TJacob
TJacob

Reputation: 133

Java Package with hyphen in name

How do I import a package named "poof-support" .

No, I can't change the package name, I'm getting an: error '.' expected . The line giving the error is:

import poof-support.exception;

Upvotes: 10

Views: 12821

Answers (2)

Johny
Johny

Reputation: 2188

You can't have - in your package name. So you will need to change the name.

Some Package Naming Conventions from java Documentation

  • Package names are written in all lower case to avoid conflict with the names of classes or interfaces.

  • In some cases, the internet domain name may not be a valid package name. This can occur if the domain name contains a hyphen or other special character, if the package name begins with a digit or other character that is illegal to use as the beginning of a Java name, or if the package name contains a reserved Java keyword, such as "int". In this event, the suggested convention is to add an underscore. For example:

  incorrect names                | correct names
  ---------------------------------------------------------  
  hyphenated-name.example.org    | org.example.hyphenated_name
  example.int                    | int_.example
  123name.example.com            | com.example._123name

check this link for naming conventions of package.

Upvotes: 26

JB Nizet
JB Nizet

Reputation: 691993

You will have to change its name, since it's illegal to use a dash in a package name. The recommendation is to use an underscore instead.

Upvotes: 8

Related Questions