안녕하세요, 저는 개체와 참조를 분석 할 때 기본적인 의심을 가지고 있습니다.개체 및 참조가있는 Java 배열
int a; //here we are creating an object a of type integer
Integer b=new Integer(); // here we are creating a reference variable b points to an object of type Integer in heap.
각각의 장점은 무엇입니까? 어디에서 "int a"와 다른 하나를 사용할 수 있을까요 ?? 어레이의 경우
,
int[] a=new int a[5];
경우 이유있다 "는 값 int" "int로 A [5]"아래의 코드가 널 포인터 예외가 발생하기 때문에, 불가능
int a[5];
a[0]=10;
System.out.println(a[0]); //gives null pointer exception
int[] a=new int[5];
a[0]=5;
System.out.println(a[0]);
왜 경우 전자의 경우는 참조를 제외하면 생성 될 필요가있을 때 코드는 잘 작동 "int a"가 작동하면?
'int a [5];는 Java에서 구문 오류이며'int a [5] = null; '이 될 것이라고 생각합니다. [JLS §8.3] (http://java.sun.com/docs/books/jls/third_edition/html/classes.html#40898)을 참조하십시오. 대괄호 안에는 아무것도 들어 있지 않습니다. –
@ Paŭlo Ebermann, 좋은 관찰. 감사 –