Kotlin से Ruby
Recorder: polyglot Kotlin adapter (kotlinc + Java driver)। Top-level functions record किए जा सकते हैं।
Ktor और Spring (Kotlin) routes को analyze ढूँढ लेता है; Spring के लिए java.md पढ़ें।
Constructs
- Null safety:
String?->nilहो सकता है;?.->&.;?:->||(जब false कोई value न हो) या.nil? ? d : x;!!->NoMethodErrorजैसे errors सिर्फ़ वहीं raise करें जहाँ कोई recorded case उन्हें दिखाए। - Errors:
require(cond) { msg }->raise ArgumentError, msg unless cond;check()->RuntimeError(IllegalStateException);error(msg)->raise msg। - Data classes ->
Data.define(value equality,copyके लिएwith)। - Sealed classes /
when->case ... inpattern match या class परcase। - Collections:
map/filter/fold/groupBy/associateBy/sumOf/joinToString->map/select/reduce/group_by/index_by/sum/join।listOfimmutable है: अगर mutation एक bug होगा तोfreezeकरें। - Ktor:
get("/x/{id}") { call.respond(HttpStatusCode.OK, x) }-> route +render json:।
Traps
- Java वाले ही numeric traps:
Intoverflow wrap होता है,/zero की ओर truncate करता है,%dividend का sign लेता है (remainder),roundToInt()half up, +infinity की ओर round करता है (2.5 -> 3,-2.5 -> -2)। String.lengthUTF-16 units गिनता है; जहाँ Rubynilलौटाता है, वहाँsubstringStringIndexOutOfBoundsExceptionthrow करता है (->IndexError)।- String पर
toInt()NumberFormatExceptionraise करता है (->ArgumentError,Integer(s)की तरह);toIntOrNull()->Integer(s, exception: false)।