Explain Kotlin code
Paste Kotlin and Vibe explains where null can turn up, what a data class writes for you and where an extension function comes from.
Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Google Gemini to write the explanation. Don't paste keys or passwords. Common key formats are refused.
Vibe12 lines selected
Press Explain it for the sample, or paste your own code first.
What this Kotlin sample shows
- null safety
noteis aString?, so it may be null, and it is unless you pass one.note?.trim()callstrimonly when there is a note, and?: "no note"fills in when there isn't. Writenote.trim()and the compiler stops: only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of typeString?.- extensions
fun Parcel.label()andfun Parcel.withExtra()add functions toParcelfrom outside the class, sopackingLabelscan callit.label()as if it were a method. Inside them,code,grams,noteandcopybelong to the parcel they were called on.- data classes
data classwritesequals,copyand destructuring for the three properties.withExtra(25)returns a 525 g copy and leaves the 500 g original as it was,original == original.copy()istrue, andval (code, grams, note) = originalgivesBOX,500andnull.
Good to know
packingLabelsturns a 500 gBOXwithout a note and a 100 gBAGwhose note isfragilewith two spaces on each side intoBOX: 500 g (no note)andBAG: 100 g (fragile).withExtrachanges onlygrams: the copy keeps the original'scodeandnote, and the two parcels are not equal.- An empty list of parcels gives an empty list of labels.
Watch out: ?: only steps in for null. A note of three spaces trims to an empty string, which isn't null, so a 20 g ENV parcel with that note gets the label ENV: 20 g (). note?.trim()?.ifBlank { null } ?: "no note" gives no note for it.
Explain Kotlin code beside your editor
Unvibe is a free app for Mac and Windows. In the app there is no pasting: select code in any app and press Control+U (Ctrl+Alt+U on Windows).