javaandroidimportlibrary-project

Android Studio - why import statement is unused/not needed?


In an Android studio library project, the following code piece gives error.

package my.package.a;

import my.package.b.Test;  //this shows unused, why??

public class **Test** extends my.package.b.Test { //"Test is already defined in this compilation unit." why? 
    ...
}
  1. extends my.package.b.Test this line is using package b, isn't it? so why the import statement shows unused?

  2. These two Test classes are in different packages, why does it have name conflicts??

Solution:

  1. Refer to full name and delete import statement.
  2. Cannot import my.package.b.Test as it's in conflict with current class name.

Solution

  • The import is not needed here because you're already calling out my.package.b.Test by full name. If you use the fully qualified reference to a symbol, there is no need to import it.