지금은 이진수를 나타내는 int로 this interface을 구현하려고합니다.Java의 인터페이스, 클래스 및 생성자 이해
나는 to string();
을 구현해서는 안되지만, 내가 필요하다고 가정 해 봅시다. 이것은 내가 지금까지 쓴 것입니다
:
public class IPAddressInt implements IPAddress {
private int ipAdress;
public IPAddressInt(int num1,int num2, int num3, int num4){
String n1=Integer.toBinaryString(num1);
String n2=Integer.toBinaryString(num2);
String n3=Integer.toBinaryString(num3);
String n4=Integer.toBinaryString(num4);
String finalString=n1+n2+n3+n4;
this.ipAdress=Integer.parseInt(finalString);
}
public String toString() {
return this.toString();
}
내가 this.ipAdress.toString();
또는 ipAdress.toString()
컴파일러를 반환하는 트링있을 때 그 그것을 Cannot invoke toString() on the primitive type int
, 을 말한다 내가 쓰는 경우에만 this.toString();
그것을 작동합니다. 왜? int가 문자열로 변환 될 수 있다는 것을 알고 있습니다. 그리고 어떻게 this
이 작동하고 전체 구문이 올바르지 않습니까? 그것은 동일하지 않아야합니까? 어쨌든 내가 원하는 것을 얻을 수 있을까요?
감사합니다.
@Andrew : Lol. 나는 그것을 바꿨다. –
유머 감각과 상식을 모두 가지고있어 기쁩니다. :-) 당신이 만족스러운 해결책을 얻기를 바랍니다. –