본문 바로가기
[Kotlin Tutorial] Operator overload 와 convention #1 - Chap7. Operator overloading and other conventions [Kotlin Tutorial] Operator overload 와 convention #1 - Chap7. Operator overloading and other conventions 참조 : Kotlin in action -Java 에는 특정 class 에 결속되어 있는 언어적 기능이 있다.예를 들어 Iterable 를 구현하면 for loop 에서 쓸 수 있고, AutoCloseable 을 구현하면 try-with-resources 에서 사용할 수 있다. Kotlin 도 비슷한 것들이 있다.그러나 specific type 에 결속된 것이 아니라 specific name 에 결속되는 기능들이 있다.예를 들어 plus 라는 이름으로 class 에 function 을 추가하면, + operator 를 해.. 2017. 8. 24.
[Kotlin Tutorial] Kotlin 의 Type system #2 [Kotlin Tutorial] Kotlin 의 Type system #2 참조 : Kotlin in action 6.2. Primitive and other basic types 6.2.1. Primitive types: Int, Boolean, and more -Kotlin 은 primitive type 과 wrapper type 을 구분하지 않는다. -그렇다면 Int 가 object 라면 Kotlin 은 모든 primitive type 을 실제로 object 로 만드는가?당연히 그렇게 안 했다.compiler 가 대부분의 Int type 을 Java 의 primitive type 으로 변형시킨다.generic, collection 등은 원래 Java 의 Integer 형태만 담을 수 있으므로 이 경.. 2017. 8. 22.
[Kotlin Tutorial] 클래스, objects, 그리고 인터페이스 #2 [Kotlin Tutorial] 클래스, objects, 그리고 인터페이스 #2 참조 : Kotlin in Action 4.3. Compiler-generated methods: Data classes and Class delegation 4.3.1. Universal object methods -Java 에서 == 는 primitive 나 object 의 reference 를 비교하는 것.Kotlin 에서는 == 가 기본비교이다. equals 를 호출해서 비교한다.그럼 Java 에서의 == 는? === 로 대체된다. 4.3.2. Data classes: autogenerated implementations of universal methods -data class Client(val name: Stri.. 2017. 8. 14.
[Kotlin Tutorial] 클래스, objects, 그리고 인터페이스 #1 - Chap4. Classes, objects, and interfaces [Kotlin Tutorial] 클래스, objects, 그리고 인터페이스 #1 - Chap4. Classes, objects, and interfaces 참조 : Kotlin in Action 4.1. Defining class hierarchies 4.1.1. Interface in Kotlin -Kotlin 의 interface 는 Java8 과 비슷하다.abstract method 를 가질수도 있고, Java8의 default method 도 가질 수 있다. ( Java8 과는 다르게 default keyword 는 필요없다 )단, state 는 여전히 가질 수 없다. ( 실제 variable ) -Kotlin 에서 interface 정의는 아래와 같다.interface Clickable{ fun.. 2017. 8. 11.
[iOS Study] 병렬 프로그래밍 가이드 ( 병렬 앱 디자인 ) [iOS Study] 병렬 프로그래밍 가이드 ( 병렬 앱 디자인 ) https://developer.apple.com/library/ios/documentation/General/Conceptual/ConcurrencyProgrammingGuide/ConcurrencyandApplicationDesign/ConcurrencyandApplicationDesign.html#//apple_ref/doc/uid/TP40008091-CH100-SW1 -전통적 방법으로의 복수개의 코어를 사용하는 방법은 여러개의 thread 를 만들어 사용하는 것이다.그러나 thread 를 사용한 코드는 scale 측면에서 좋지 않다.core 가 처리하기 좋은 thread 의 갯수를 아는 것도 쉽지 않고, thread 들을 효율적으.. 2017. 7. 1.
[iOS] Java 의 equals 구현하기 [iOS] Java 의 equals 구현하기 -iOS 의 NSObject 의 (BOOL)isEqual:(id)object 가 equals 함수에 매칭하는 함수이다. -Java의 instanceof 는 [NSObject isKindOfClass:[TargetObject class]] 를 통해 확인할 수 있다. -isEqual 을 override 할 때는 (NSUInteger) hash 함수도 override 하는 것이 좋다. bool, CLASS, equals, hash, ID, instanceof, IOS, isEqual, iskindofclass, Java, nsobject, nsuinteger, object, override, [iOS] Java 의 equals 구현하기 2017. 6. 27.
[Java] Subclass 는 Serializable 을 구현하고, Superclass 는 그렇지 않은 경우. [Java] Subclass 는 Serializable 을 구현하고, Superclass 는 그렇지 않은 경우. 출처 : http://www.jguru.com/faq/view.jsp?EID=34802 Object 를 serialize 를 하면 상속 hierarchy 를 따라가며 직렬화 메커니즘을 수행한다. 이 과정에서 만약 Serializable 을 구현하지 않은 super class 를 만나면 이 매커니즘은 멈추게 된다. Deserialize 할 때 Serializable 을 구현하지 않은 super class 는 stream 으로부터 복구되는 것이 아니라, empty argument constructor 가 호출되며 복구된다. 따라서 Superclass 의 내용을 복구해줄 필요가 없다면 그냥 igno.. 2017. 5. 16.
[Java] Condition 은 어떻게 쓰는걸까? 예를 통해 함 보자. - Condition 에 대해 예로 잘 등장하는 코드는 아래와 같다. ( Oracle Java Doc 에 나와 있는 코드 ) /** * 이 Buffer 는 array index 재배치를 하지 않고, front 와 rear 값을 두고 control 해서 rear < front 일수도 있는 형태이다. */ public class BoundedBuffer { private final String[] buffer; private final int capacity; private int front; private int rear; private int count; private final Lock lock = new ReentrantLock(); private final Condition notFull = loc.. 2017. 5. 12.
[Java Concurrency] 동기화 클래스 구현 14.1. 상태 종속성 관리 - 병렬 객체의 상태 종속적인 메소드는 선행 조건이 만족하지 않았을 때 오류가 발생하는 문제에서 비켜날 수도 있겠지만, 비켜나는 일보다는 선행 조건을 만족할 때까지 대기하는 경우가 많아진다. - 자바에 내장된 조컨 큐 메커니즘(condition queue mechanism)은 실행 중인 스레드가 특정 객체가 원하는 상태에 진입할 때까지 대기할 수 있도록 도와주며, 원하는 상태에 도달해서 스레드가 계속해서 실행할 수 있게 되면 대기 상태에 들어가 있던 스레드를 깨워주는 역할도 담당한다. - 일단 선행 조건을 만족하지 않았다면 락을 다시 풀어줘야 다른 스레드에서 상태 변수를 변경할 수 있다. 만약 락을 풀어주지 않고 계속 잡고 있다면 다른 스레드에서 상태 변수의 값을 변경할 수 .. 2017. 5. 8.
반응형