Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to initialise java object from kotlin

Tags:

java

kotlin

I am new to kotlin and I want to initialize object from java class in Kotlin class.

I have java class Car for example com.myapp.vehicles.car

in java I would do

buss = new car()

then call buss.drive()

how do I do same from kotlin.

I have tried var buss = car.getinstance() but there is no method getinstance

like image 276
wpj Avatar asked May 06 '26 04:05

wpj


2 Answers

getInstance() method created by itself for initialization.

in Java

buss = new car()
call =buss.drive()

In kotlin

var buss = car()
var method = buss.drive()
like image 99
Hemant Parmar Avatar answered May 09 '26 00:05

Hemant Parmar


In kotlin no need to new world so just type this for new instance of class

var buss = car()

Now you can use all object and function of car class

Also i suggest use Uppercase for start letter of your classes

like image 28
Radesh Avatar answered May 08 '26 23:05

Radesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!