GithubHelp home page GithubHelp logo

kotlin_logic_tutorial's Introduction

Kotlin_logic_tutorial

코틀린의 기본기를 다지는 가이드 및 튜토리얼

[!] 코틀린의 기초 문법과 지식이 부족하다면?

[!] 코틀린 코딩 중 헷갈리는 부분이 있다면?

[!] 코틀린을 좀 더 DEEP하게 파고싶다면?

[!] 코틀린의 NEW TECH LOGIC을 공부하고싶다면?

1. Tutorial Init

  • IDE

    • Intellij ultimate
    • VS Code
  • Language

    • Kotlin

2. Tutorial List

** base(기본 문법) **


기초 문법 모음

1. var/val

2. nullable(?와 !!)

3. 조건식

4. Any와 instanceof

5. When

6. loop(for, while)

7. null과 not-null(안전 호출, 엘비스 연산자)

8. object

9. pair와 triple

10. const val

11. Destructuring Declaration

12. 변수 값으로 활용할 수 있는 try/catch 와 if절

base/BaseGrammer.kt

Companion Object

companion object는 간단하게, Java에서의 static한 느낌의 singleton object 라고 이해하면 된다.

base/CompanionObject.kt

by lazy와 lateinit

lateinit은 처음 값의 Type만 지정해주고, 실제 값까지 함께 선언하지 않는다. 이후에 값을 지정해줘야 함

by lazy는 read-only 느낌으로, 변할 수 있는 값을 활용해 고정 값을 대입할 때 주로 사용된다. val만 선언 가능

base/Lazy.kt

기초적인 Class 선언

case 1. default 선언

case 2. 생성자의 parameter가 없을 경우 () 생략 가능

case 3. class parameter에 var/val 변수를 선언하면, 클래스 내부 멤버변수 및 생성자 선언을 동시에 할 d수 있다.

case 4. class parameter에 일반 변수를 받게 되면, 클래스 내부 멤버변수로 선언되지 않는다.

case 5. class parameter로 받은 일반 변수 값을 클래스 내부 멤버변수에 초기화한다.

case 6. init(기본 생성자가 호출된 직후 바로 실행되는 코드 블럭

case 7. constructor(보조 생성자. 추가적인 생성자 함수를 작성하고 싶을 때 활용)

case 8. class parameter에 받은 일반 변수의 Default 값 설정 가능.

case 9. open class

case 10. 상속과 구현 차이

case 11. protected 및 internal

c

case 12. nested class / inner class

case 13. inner class의 outer class 자원 사용 방법

case 14. data class

base/BaseClass.kt

Scope function

Scope function은 상위 Context Object를 코드 블럭 내에서 활용해 만들고, 이를 실행할 수 있게 하는 함수. (자유롭게 연계 가능)

let

run

apply

also

with

takeIf / takeUnless

base/Scope.kt

by로 Delegate Pattern을 쉽게 구현

Delegate Pattern은 디자인 패턴 중 하나로, 어떤 기능을 자신이 처리하지 않고 다른 객체(대리인)에 위임시켜서 그 객체가 일을 처리하도록 하는 것

다른 객체(대리인)가 만들어놓은 방식(코드) 그대로 가져와서 사용해야하는데, 인터페이스다보니 사용할 때마다 그대로 코드를 가져오는 것은 낭비.

-> by 키워드를 통해 interface를 구현한 parameter 객체의 코드를 그대로 가져올 필요가 없고, overriding하지 않아도 된다.

base/Delegate.kt

Reified / inline

Reified는 Kotlin -> Java의 Runtime 시점에 Generic Type을 알고 싶을 때 사용. Reified를 사용하게 되면 Generic Class Type 정보까지 함께 전달 가능

(참고) 무조건 inline 과 함께 사용해야 한다.

inline function는 inline function은 kotlin -> java의 컴파일 단계에서 "함수 호출 = invoke" 방식이 아닌 "코드 복사" 방식으로 코드 변환해줌.

base/Reified.kt

sealed class

sealed class를 super class로 하는 하위 클래스(child class)의 종류를 제한하고, 이를 컴파일러에게 알려주기 위해 사용.

-> Enum과의 가장 큰 차이점은, Enum은 single instance 이지만, sealed class는 여러 개의 하위 클래스 객체를 생성할 수 있다.

base/Sealed.kt

vararg

가변인자. 즉, 매개변수의 개수를 동적으로 지정해 줄 수 있게 하는 변수.

base/Vararg.kt

enum

Enum은 Kotlin에선, Comparable Interface를 구현하는 Abstarct class.

base/Enum.kt

contract / callsInPlace

contract는 함수가 컴파일러가 이해하는 방식으로 동작을 명시적으로 설명할 수 있도록 한다.

callsInPlace는 람다 함수를 사용할 때, 그 함수의 호출 횟수를 명시적으로 컴파일러에게 이해시켜주기 위해 사용

contract/Contract.kt

collections / sequences

collections : eager evaluation. 즉시 실행

sequences : lazy evaluation. 늦은 실행. kotlin에서 Collections와 마찬가지로 Iterable한 자료구조

collections/Sequences.kt

Coroutine

suspend function

비동기 실행중인 coroutine 함수를 잠시 중지시킬 수 있는 함수를 설정(표시)한 것.

coroutine/SuspendFunc.kt

Annotations

Kotlin -> Java로 컴파일되는 과정에서 활용되는 Annotations.

@JvmField

@JvmStatic

@JvmName

@Throws

@JvmOverloads

@JvmInline

(특별추가) value class

jvm/Annotations.kt

3. Tutorial Description



4. Maker : Leehaewon



etc.

kotlin_logic_tutorial's People

Contributors

201402407 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.