ä»æ´ãªããï¼ï¼ï¼Kotlinï¼ã³ããªã³ï¼ã¨ããããã°ã©ãã³ã°è¨èªã«èå³ãæã£ãã®ã§èª¿ã¹ã¦ãã¾ãã
åèãµã¤ãï¼Welcome - Kotlin - Confluence
Kotlinã¯å»å¹´ã®7æã«çºè¡¨ãããè¨èªã§
- JetBrainsã«ããéçºããã¦ãã
- JVMåãã®éçåä»ãããã°ã©ãã³ã°è¨èª
- å·¥æ¥å©ç¨åã
ã¨ããç¹å¾´ãæã£ã¦ãã¾ãã
ä¸è¨åèãµã¤ãã«ããã¨ãKotlinã®ãã¶ã¤ã³ã´ã¼ã«ã¯
- Javaã¨ã®äºææ§ããã£ãè¨èªãä½ããã¨
- ã³ã³ãã¤ã«ã®éããå°ãªãã¨ãJavaã¨åç
- Javaããå®å ¨ã«ãããããè½ã¨ãç©´ï¼NULLãã¤ã³ã¿ã¸ã®éæ¥åç §ã®ãããªï¼ã®éçãªãã§ãã¯
- Javaããç°¡æ½ã«ãåæ¨è«ãã¯ãã¼ã¸ã£ãextension functionsãªã©ã®ãµãã¼ãã«ããå®ç¾
- æç¨ãªè¡¨ç¾åãç¶æãã¤ã¤ãæãæçãã競åï¼Scalaï¼ãããã·ã³ãã«ã«
ã¦ãªæãã§ãã
ä»ã®ã¨ãããã³ã³ãã¤ã©ã¯ããã¾ããã
ã³ã³ãã¤ã©ã¯IntelliJ IDEAï¼JetBrains製ã®IDEï¼ã¨ä¸¦è¡ãã¦éçºããã¦ããããã§ãã
ä¸è¨åèãµã¤ãã«ããã¨ãå»å¹´ã®æ®ãã«æåã®ãã¼ã¸ã§ã³ãåºãäºå®ã ã£ããããã§ãããåºã¦ãã¾ããã
Kotlinプロジェクトのブログã®1月4日の記事ã§å¤§ããªæ§æã®å¤æ´ãçºè¡¨ãããã®ã§ãã³ã³ãã¤ã©ç»å ´ã¾ã§ããå°ããããããã§ãã
Kotlinã¯ååããã´ãããããããèå³æ·±ãæ©è½ãããããæã£ãè¨èªãªã®ã§ãä»å¾é常ã«æ³¨ç®ãããè¨èªã«ãªãã®ã§ã¯ãªãã§ããããã£ï¼ï¼ï¼
æå¾ã«ãããã ãã§ã¯ã¤ã¾ããªãã¨æãã®ã§ã³ã¼ãä¾ãã
ã¾ã ã¾ã Kotlinã«ã¤ãã¦ç¥ããªããã¨ã ããã§ãããFizzBuzzæ¸ãã¾ãã(*ï¿£âï¿£*)
fun main(args : Array<String>) { for(i in 1..10) { if(i.isFizz()) { print("Fizz") } if(i.isBuzz()) { println("Buzz") } else if(i.isFizz()) { println() } else { println(i) } } } fun Int.isFizz() : Boolean { return this % 3 == 0 } fun Int.isBuzz() : Boolean { return this % 5 == 0 }
ä¿®æ£ï¼2012-01-14 0:14ï¼
Kotlinã®æ©è½ãã§ããã ãå¤ã使ã£ããã¼ã¸ã§ã³ã§ãã
fun main(args : Array<String>) { iterate(1..100) { val strBuilder = StringBuilder() if(it.isFizz()) { strBuilder += "Fizz" } if(it.isBuzz()) { strBuilder += "Buzz" } if(strBuilder.length() == 0) { strBuilder += it.toString() } val str = strBuilder.toString() System.out?.println(str) } } //Higher-order function fun iterate(range : IntRange, function : (n : Int) -> Unit) { for(n in range) { function(n) } } //Single-expression functions //Extension functions fun Int.isFizz() = this % 3 == 0 fun Int.isBuzz() = this % 5 == 0 //Operator overloading fun StringBuilder.plusAssign(obj : Any) { this.append(obj) }