Binary Journey

[Java] Why does the string data type have a .toString() method? 본문

Java | Spring

[Java] Why does the string data type have a .toString() method?

binaryJournalist 2021. 4. 5. 14:46
반응형

 

 

String 클래스는 이미 String 인데 왜 toString() method 를 가지고 있을까

 

그냥 궁금해졌다.

 

 

근데 나와 같은 궁금증을 가진 사람이 많나 보다.

 

 

 

C# 이긴 한데 Java도 별반 다를 바 없을 거 같아서 주소를 가져왔다,

 

stackoverflow.com/questions/2778827/why-does-the-string-type-have-a-tostring-method

 

Why does the string type have a .ToString() method?

Why does the string data type have a .ToString() method?

stackoverflow.com

 

String 의 가장 상위 클래스가  Object이고 String은 Object의 하위 클래스라서 toString을 가지고 있다고 한다.

 

그러나 String 의 toString은 override 하여 Object와 달리 자기 자신, 자기 자신의 값을 리턴한다고 한다.

 

다음 블로그에도 설명이 되어있다.

 

selfdevelope.tistory.com/560

 

자바 String toString()

Object 이란 모든 클래스의 가장 최상위 클래스인 "Object" 클래스 JAVA에 제공하는 모든 클래스들의 계층 구조로 되어있고, 그 최상위로 올라가면 "Object"이라는 클래스가 존재한다. 우리가 일반적으

selfdevelope.tistory.com

 

반응형