-
Notifications
You must be signed in to change notification settings - Fork 7
[3주차] ldh #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3주차] ldh #21
Conversation
Livenow14
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사소한 부분을 추가하면 완벽해질 것 같아요
|
|
||
| * 위 코드를 보면 dong은 static으로 hyun 은 인스턴스 변수로 선언을 하였다 그후 클래스 객체를 2개 선언 한후 d1 클래스에서만 증가를 해줬는데 d2클래스를 출력했을때 static 으로 선언한 값이 증가 한것을 볼수 있다. 이는 static으로 선언된 변수는 모든 인스턴스가 하나의 저장 공간을 공유 하기 때문이다. (나는 보통 cnt 값을 셀때 쓴다) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋은예제, 하지만 이렇게 클래스의 static 인스턴스가 공유참조 되었을때 생기는 문제도 다뤄봤으면 좋을거 같아요
ex) d1을 변경했는데 d2에서도 추가되는 문제 등.
주로 이러한 문제 때문에 상수라는 것을 주로 쓰곤합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했습니다.
| ### 타입 추론, var | ||
| ** 타입 추론(Type Inference)** | ||
| * 타입 추론은 정적 타이핑을 지원 하는 언어에서 타입이 정해져 있지 않은 변수에 대해 컴파일러가 자동으로 변수의 타입을 추론해 낼수 있도록 하는 기능이다. | ||
| * 타입 추론이 가능 하다 -> 코드량이 줄어든다, 코드의 가독성이 높아진다. | ||
| _예젼에 노드 js 를 공부할때 var 을 정말 많이 봤었었는데 이제 자바10이상부터는 자바에서도 var 사용이 가능하다 한다._ | ||
| * 이전 자바에서는 자바의 변수를 선언 할때 변수 타입을 명시해줬었다. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var에서 말고도 다른곳에도 타입 추론이 일어나는 곳이 많습니다.
이것도 추가해보는 게 좋을 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했습니다.
| --- | ||
| > 이번 과제를 하면서 느낀건데 그 동안 자바 컨벤션을 무시하고 코드를 작성하는 경우가 많았던것 같다. 앞으로는 최대한 자바 컨벤션을 지켜가면서 코드를 작성해야겠다. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이전 코드 습관을 회고(리팩토링)해보는 것이 실력 향상에 많이 도움이 되는 거같아요.
좋은 생각입니다.
| * 자바 7의 다이아몬드 연산자 방식을 var 과 함께 사용하면 컴파일 에러가 발생한다. | ||
| ``` java | ||
| var message = new ArrayList<>(); //불가능 | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
불가능의 이유??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했습니다.
| if (i == a) { | ||
| return false; | ||
| } ==> O | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 코드 컨밴션 중요!
| * 클래스 이름에 명사 사용 | ||
|
|
||
| * 클래스 이름은 명사나 명사절로 짓는다. | ||
| ``` java | ||
| public class sum{ | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
잘못된 예제인거죠?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했습니다.
3week/3week.md
Outdated
| * 메서드의 이름에 소문자 카멜법 적용, 메서드 이름은 동사/전치사로 시작 | ||
|
|
||
| * 이건 toString() 을 생각하면 이해하기 쉽다. | ||
| To + String 인데 소문자 카멜 표기법으로 인해 단어의 첫 문자가 소문자가 되고 그 다음 오는 단어의 첫 문자가 대문자가 되어 toString() 이 된다. | ||
| ``` java | ||
| toString() renderHtml() | ||
| ``` | ||
| * 상수는 대문자와 언더스코어로 구성 | ||
|
|
||
| * 상태를 가지지 않고 static final로 선언되어있는 필드를 상수라 하는데 이 상수는 대문자로 작성하고 복합어는 (_)로 구분한다. | ||
| ``` java | ||
| public final int UNLIMITED = -1; | ||
| public final String POSTAL_CODE_EXPERESSION = "POST"; | ||
| * 변수에 소문자 카멜표기법 적용 | ||
|
|
||
| * 이는 위에서 메서드 이름 부분에 예를 들어놨으니 생략 하겠다. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
명사, 클래스이름은 어떻게 시작하나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했습니다.
| * 임시 변수를 제외 하고는 한글자 금지 | ||
|
|
||
| * 메서드 블럭 범위 이상의 생명주기를 가지는 변수에는 1글자로 된 이름 사용 X but 반복된 인덱스나 람다 표현식의 파라미터등의 짧은 범위의 임시 변수에는 사용 가능 | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정말 중요한 부분!
No description provided.