Keywords in Kotlin (fun #4)

Aung Ye Htet
Jan 30, 2021

--

ဒီတစ်ခေါက်‌တော့ Kotlin ရဲ့ Function Type တွေအကြောင်း လေ့လာကြမယ်..

Kotlin Languageကို တည်ဆောက်တုန်းက Java ကို မှီငြမ်းခဲ့ကြတယ်ဆိုပေမဲ့ Kotlinမှာ OOP အပြင် Functional Programming (FP)ကိုပါ ရေးလို့ရတယ်။

FPမှာ functionတွေကို အဓိကထားသုံးကြတယ်။ functionတွေသည် first-class တွေဖြစ်ကြတယ်။

“ငါတို့ကို variableတွေ မှာ Assign လုပ်လို့ရတယ်။ တခြား function တစ်ခုမှာ Argument အနေနဲ့ ထည့်ပေးချင်လည်း ရတယ်ကွာ။ Return Value မှာ သုံးချင်လည်း လာထား အေးဆေးပဲ”

တနည်းအားဖြင့် ပြောရရင် FPမှာ function တွေက အခရာ ကျတယ်ပေါ့။

အဲလိုပဲ Kotlin Language မှာလည်း function တွေက Type တစ်ခုအ‌‌နေနဲ့ သတ်သတ်ရှိကြတယ်။

အပေါ်က Kotlin Codeမှာ isEven သည် Function Type ဖြစ်တယ်။ ခေါ်သုံးတဲ့အခါလည်း ရိုးရိုး function တွေအတိုင်းပဲ Parentheses “()” နဲ့ ခေါ်သုံးလို့ရပါတယ်။

Function Type ကို ကြေညာတဲ့ပုံစံ အလွယ်ပြရရင် ဒီလိုမျိုးလေးပေါ့

Kotlinရဲ့ Named Function တွေကို Function Type အနေနဲ့ အသုံးပြုလို့မရဘူး ဆိုတာ‌တော့ သတိချပ် ဖို့လိုမယ်‌နော်။

Named functionကို variable ထဲ Assign လုပ်လို့မရနိုင်ပါဘူး။

Kotlin Language မှာ Function Type ရဲ့ instanceကို တည်ဆောက်လို့ရတဲ့ နည်းလမ်း ၄ မျိုးတောင် ရှိတယ်..ဗျ

1. Lambda Expression
2. Anonymous Function
3. Callable Reference
4. Custom Class

ဆိုပြီးပေါ့။

သူတို့အကြောင်းအသေးစိတ်ကိုတော့ နောက်Article တစ်ခုမှာပဲ ထပ်လေ့လာကြတာပေါ့ဗျာ..

See you soon…

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Aung Ye Htet
Aung Ye Htet

Written by Aung Ye Htet

Android Developer, Kotlin Enthusiast

No responses yet

Write a response