fun main() {
aa()
aa()
}
fun aa() {
print("Kotlin")
}
// Kotlin
// Kotlin
fun main() {
var result = addUp(1,23)
gogo("result is $result") // result is 24
}
fun gogo(a: Int, b:Int) : Int {
return a + b
}
fun 함수명(변수:타입, 변수: 타입 ... ) : 리턴타입 { return 리턴값 }
:
변수 : 타입
형식으로 parameter를 넣어준다.
fun argument(parameter) : returnType {return }
: parameter를 넣어 호출하는 것을 argument(인자)라고 한다.
객체 지향 언어로 클래스 안에 있는 함수를 ‘메서드(method)'라고 부르고, 클래스 밖에 있으면 ‘함수(function)이라고 부른다. 더 정확하게는 kotlin에서 fun은 method를 포함하는 개념이므로 method를 지칭할 수 있을 때는 function보다 method라고 부르는 게 좋다.
이에 자세히 설명된 글이다.
참고 - https://blog.kotlin-academy.com/kotlin-programmer-dictionary-function-vs-method-vs-procedure-c0216642ee87