performance - Does an unused import declaration eat memory, in Java? -


does unused import - import android.widget.relativelayout; eat memory? want know how or valuable? maybe stupid question, haven't found answer.

no don't take memory. imports used compiler resolve class names @ compile time.

compiler changes each class name qualified name. , removes import statement. so, import statement doesn't make byte code.

the issue can come wildcard import namespace conflict, i.e., when 2 types same name defined in 2 different packages, importing packages wildcards cause name conflict type used.


to see how compiler replaces import statement, can generate byte code of class using javap command. consider below code:

import java.util.*; import java.util.regex.*;  public class test {     public static void main(string[] args) {      } } 

just compile above code, , check byte code using following command:

javap test 

it gives out following output:

public class test {   public test();   public static void main(java.lang.string[]); } 

so, can see string type replaced it's qualified name java.lang.string, , there no import statement in byte code.


Comments

Popular posts from this blog

mod rewrite - Using "?" when rewriting the URL -

.htaccess: Transfer name to index.php if not directory public -

Admob integration with pygame in android -