Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Are you using Kotlin with Spring 5?

 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my quest to learn both Kotlin and Spring I've started going through this book Learning Spring Boot 2.0 - Second Edition which can be found here:
https://www.packtpub.com/application-development/learning-spring-boot-20-second-edition.
However instead of programming in Java I'm programming in Kotlin.

Currently I'm about a quarter of the way done the book and run into an issue or two, which I have been able to overcome for the most part.
Yet, I suspect that there will be other challenges a head.

I'm wondering, are you using both Kotlin and Spring 5?

By the way I have picked up a few other books on Spring 5 with which I hope to use to learn both Kotlin and Spring 5.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been using Kotlin at work, so far only for a few little tools that I use myself.  I haven't yet used it extensively with Spring 5 yet.

Spring 5 does officially support Kotlin; the Kotlin support in Spring 5 mainly consists of two things: (1) making sure many things are annotated with @Nullable / @NonNull annotations so that it plays nice with Kotlin's null-safe type system, and (2) a number of extension methods to make working with Spring more convenient.

I've found, and I've seen from other projects / people using Kotlin, that extension methods are one of the most useful and powerful features that people pick up once they're going beyond the basics with Kotlin.

I like Kotlin a lot, and I hope I get the chance to use it a lot more in future projects.
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As strange as this may sound, I'm just trying to keep it simple right now.
So I have not ventured into the extension methods or using annotations yet.

I did recently see an article stating that extension methods get compiled into static methods when transformed into bytecode.
As a result the more extension methods you have, the more static methods you have, and people have different views on static methods.

I know that my both my Java, Spring and Kotlin knowledge base is not as strong as some others out there.
Once I do get better at both Spring and Kotlin I do have a project in mind which will not only use Spring and Kotlin, but Android as well.

I do like the fact that you have have both Java files and Kotlin files in the same project allowing you to mix and match as you see fit.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pete Letkeman wrote:I did recently see an article stating that extension methods get compiled into static methods when transformed into bytecode.
As a result the more extension methods you have, the more static methods you have, and people have different views on static methods.


If you write Java code with lots of static methods, then you're probably doing something wrong - you're most likely writing non-object-oriented, procedural code. But that is not really relevant for Kotlin extension methods - the fact that the Kotlin compiler happens to implement extension methods under the covers using static methods on the JVM doesn't make extension methods somehow bad.

Extension methods are a way to add methods to existing classes after the fact - or, that's what they seem to be at first sight.

In Java, people often create "utils" classes. Maybe you've written a StringUtils class yourself or used methods from such a class. Several well-known libraries have their own sets of "utils" classes, for example Apache Commons Lang and Spring both have their own StringUtils classes with utility methods for strings.

With Kotlin, instead of creating utility methods in a StringUtils class, you can create extension methods for class String instead. You can call these extension methods on String objects, and calling such a method looks exactly the same as calling any other method from class String:

Extension methods are not really dynamically added to a class - they are instead like any other external method, so they can for example not access the private variables of the class they are designed for.
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting, thank you Jesper.

I know that I still have lots to learn, not only about Kotlin and Spring, but also Java and Android.
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!