Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there reserved package names in Java?

Tags:

java

I have a package com.test.mythingimport. Ideally, I want this to be called com.test.mything.import. Are you able to name things with import or will it cause conflicts?

like image 811
John Lippson Avatar asked Jul 27 '18 21:07

John Lippson


Video Answer


1 Answers

From JLS §7.4.1

A package declaration in a compilation unit specifies the name (§6.2) of the package to which the compilation unit belongs.

PackageDeclaration:
 {PackageModifier} package Identifier {. Identifier} ; 

where Identifier is defined in JLS §3.8 as

Identifier:
 IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral 

So a package name can specifically not be a keyword (such as import), a Boolean (true or false) or null.

like image 197
Silvio Mayolo Avatar answered Oct 12 '22 03:10

Silvio Mayolo