Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Kotlin for Android App Development: Convert Existing Java Code

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is it easy to convert existing Java code to Kotlin?

Thanks,

Frank
 
Author
Posts: 28
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank,

Good question!

For the most part, transforming existing Java code to Kotlin is straightforward. IntelliJ and Android Studio can even transform Java to Kotlin automatically (look for "Java Kotlin Converter"). However, you will have to adjust the generated code -- sometimes to make it compile but almost always to use clean, idiomatic Kotlin code.

I'd recommend to use the converter as it gives you a head start. Plus, it's actually a great way to get started with Kotlin as well because you see how it transform your Java code into Kotlin.

But keep in mind to store your original Java files somewhere (e.g. version control) because they will be gone after you use the converter.

- Peter
 
Frank Daly
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks Peter.  I'll give this a go.  

A further question - Are there instances where you should stick with Java or would you suggest coding all apps in Kotlin?

Thanks,

Frank
 
Saloon Keeper
Posts: 5815
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's also an online converter you can use: https://try.kotlinlang.org/
 
Frank Daly
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks Tim.  I'll have a look at this.

Frank
 
Peter Sommerhoff
Author
Posts: 28
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank,

Good question! I don't see any reason not to use Kotlin when starting a new app nowadays.

But I've never developed any Android games for instance. I just can't imagine any advantages Java could have here since we can use any Java libraries from Kotlin as well.

I'm open to any experience reports or other points though as to when Kotlin might not be the better choice.

- Peter
 
Frank Daly
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks again Peter and many thanks for being so polite as to write "Good question"!

Frank
 
I am going to test your electrical conductivity with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!