æ¨æ¥ã®ã¨ã³ããªã§è©±ããPlatform Type以å¤ã®M9ã§æ¹åãããè¨èªæ©è½ã«ã¤ãã¦ç´¹ä»ãããã
Non-local returns
ã³ã¼ãã®éãã§ãã
é¢æ°ãªãã©ã«å
ã§ã®return
ãåºæ¥ããã£ã¦è©±ã
ãã®ã³ã¼ããå®è¡ããã¨ã1ãã ã表示ãããã
fun main(args: Array<String>) { invoke { println("1") return // M9ããåã§ã¯ã³ã³ãã¤ã«ã¨ã©ã¼ } println("2") } inline fun invoke(f: () -> Unit) { f() }
No more local object declarations
M9ããåã§ã¯é¢æ°å ã«ãªãã¸ã§ã¯ã宣è¨ãç½®ããã
// M9ããå fun foo() { object Point { var x = 0.0 var y = 0.0 } }
ãããM9ãããã¡ã«ãªã£ãã 代ããã«ãªãã¸ã§ã¯ãå¼ã使ãã
// M9 fun foo() { // âã³ã³ãã¤ã«ã¨ã©ã¼ã«ãªã // object Point { // var x = 0.0 // var y = 0.0 // } // ãªãã¸ã§ã¯ãå¼ã§ä»£æ¿ val point = object { var x = 0.0 var y = 0.0 } }
platformStatic
Javaç¨ã«staticã¡ã½ãããå®ç¾©ã§ããããã«ãªã£ãï¼
platformStatic
ã¨ããã¢ããã¼ã·ã§ã³ãä»ããã ãã
import kotlin.platform.platformStatic object Foo { fun hoge() {} platformStatic fun fuga() {} } class Bar { class object { fun piyo() {} platformStatic fun hage() {} } }
ä¸è¨ã®Kotlinã§å®ç¾©ããé¢æ°ã¯Javaã§æ¬¡ã®ããã«å¼ã³åºããã
// Java
Foo.INSTANCE$.hoge();
Foo.fuga();
Bar.OBJECT$.piyo();
Bar.hage();
platformName
Kotlinã§ã¯ä¾ãã°ä¸è¨ã®ãããªã³ã¼ããæ¸ããã
2ã¤ã®ååã®é¢æ°succ
ããããã©ãå¼æ°ãInt
ã®Optional
ã¨Char
ã®Optional
ã
ãããåæã«å®ç¾©ã§ãã¦ãå¼ã³åºãæãåºå¥ãã¦ãããããããã
ã§ãJavaã§ã¯ãããªãã¨ã¯ç¡çãªã®ã§Javaç¨ã«å¥åãä»ããå¿
è¦ãããã
ããã§platformName
ã¢ããã¼ã·ã§ã³ã使ããããã¯Javaç¨ã®ã¡ã½ããåããã©ã¡ã¼ã¿ã«åãã
package sample import java.util.Optional import kotlin.platform.platformName fun succ(n: Optional<Int>) = n.map { it + 1 } platformName("succOfChar") fun succ(c: Optional<Char>) = c.map { (it + 1).toChar() } fun main(args: Array<String>) { println(succ(Optional.of(5))) // => Optional[6] println(succ(Optional.of('K'))) // => Optional[L] }
// Java import sample.SamplePackage; import java.util.Optional; public class Java { public static void main(String[] args) { SamplePackage.succ(Optional.of(5)); SamplePackage.succOfChar(Optional.of('K')); } }
ã¡ãªã¿ã«ä½æ°ãªãOptional#map
ãå¼ã³åºãã¦é¢æ°ãªãã©ã«ãé£ããã¦ããã©ãM9ããSAMå¤æãæ¹åãããã¿ããã
ããããã°Kotlinã®SAMå¤æãM9ã§ãããã©ã«ãå®è£
ããã£ãé¢æ°ã¤ã³ã¿ãã§ã¼ã¹ã«å¯¾ãã¦ãå¹ãããã«ãªã£ã¦ãï¼
— ããã (@ngsw_taro) 2014, 10æ 17
Private property accessors
ã³ã¼ãè¦ã¦ãããã°ãããã¨æãã
trait Foo { fun getFoo(): Int } // M9ããåã ã¨ã³ã³ãã¤ã«ã¨ã©ã¼ class FooImpl(private val foo: Int): Foo { override fun getFoo(): Int = 0 }
Foo
ãã¬ã¤ããç¶æ¿ãããã°public
ãªgetFoo()
ãå®è£
ãã義åãè² ããã©ãããã¨private
ãªããããã£foo
ãä»ã¾ã§ã¯ç«¶åãã¦ä¸æããããªãã£ããã§ãM9ããã¯å¤§ä¸å¤«ï¼