随笔分类 -  Kotlin

摘要:For example we have tow Entities: package com.virtualpairprogrammers.theater.domain import javax.persistence.* @Entity data class Performance( @Id @Ge 阅读全文
posted @ 2020-11-08 21:18 Zhentiw 阅读(114) 评论(0) 推荐(0) 编辑
摘要:pom.xml: add compile plugin <build> <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> <testSourceDirectory>${project.basedir}/src/ 阅读全文
posted @ 2020-11-06 03:38 Zhentiw 阅读(81) 评论(0) 推荐(0) 编辑
摘要:pom.xml: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <gr 阅读全文
posted @ 2020-11-05 21:06 Zhentiw 阅读(123) 评论(0) 推荐(0) 编辑
摘要:Structure: tempalates/seatBooking.html: <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>com. 阅读全文
posted @ 2020-11-05 03:30 Zhentiw 阅读(161) 评论(0) 推荐(0) 编辑
摘要:In Java, you can use Autowired to init the service: @Autowired TheaterService theaterService In kotlin, it is different, you need to use 'lateinit var 阅读全文
posted @ 2020-11-05 03:17 Zhentiw 阅读(81) 评论(0) 推荐(0) 编辑
摘要:Backing bean: A typical JavaServer Faces application includes one or more backing beans, each of which is a type of JavaServer Faces managed bean that 阅读全文
posted @ 2020-11-04 01:55 Zhentiw 阅读(63) 评论(0) 推荐(0) 编辑
摘要:Install devtool: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <option 阅读全文
posted @ 2020-11-04 01:40 Zhentiw 阅读(97) 评论(0) 推荐(0) 编辑
摘要:In Kotlin, you are able to extend a class. Just like add prototype in Javascript. fun toSentenceCase(a: String): String { return a[0].toUpperCase() + 阅读全文
posted @ 2020-11-01 22:20 Zhentiw 阅读(78) 评论(0) 推荐(0) 编辑
摘要:import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import java.util.* class AgeCalculation() { fun getAge(dob: Calendar): Int { 阅读全文
posted @ 2020-11-01 22:00 Zhentiw 阅读(149) 评论(0) 推荐(0) 编辑
摘要:In Java, when you write code in try(...), if exception throw, the resource will be closed automactially: This is not necessary in Kotlin fun printFile 阅读全文
posted @ 2020-10-30 01:39 Zhentiw 阅读(158) 评论(0) 推荐(0) 编辑
摘要:In java, it requires you to handle the exception when you declaring and using the code: public class BoringJavaCode { public static Double divide(int 阅读全文
posted @ 2020-10-30 01:37 Zhentiw 阅读(158) 评论(0) 推荐(0) 编辑
摘要:List is not mutable, when you want to add data into list, you can do is: "adding data to a mutableList", then return a immutable list by calling toLis 阅读全文
posted @ 2020-10-30 01:20 Zhentiw 阅读(371) 评论(0) 推荐(0) 编辑
摘要:(0..9).forEach(::println) (9 downTo 0).forEach(::println) (0 until 9).forEach(::println) // 0 to 8 (0..9 step 2).forEach(::println) ('A'..'F').forEach 阅读全文
posted @ 2020-10-29 01:04 Zhentiw 阅读(80) 评论(0) 推荐(0) 编辑
摘要:fun getColorType() : String { val color = getUpperFavoriteColor() return when (color) { "" -> "empty" "RED", "GREEN", "BLUE" -> "rgb" else -> "other" 阅读全文
posted @ 2020-10-28 20:58 Zhentiw 阅读(121) 评论(0) 推荐(0) 编辑
摘要:Let function is another way to solve null problem in kotlin. When you have such problem: var favoriteColor: String? = null...... return if f(avoriteCo 阅读全文
posted @ 2020-10-28 20:54 Zhentiw 阅读(55) 评论(0) 推荐(0) 编辑
摘要:In Javascript, we have: return age null ? -1 : age In kotlin, we can do the same thing with a better / simpler syntax: val safeAge: Int get() = age ?: 阅读全文
posted @ 2020-10-28 20:37 Zhentiw 阅读(114) 评论(0) 推荐(0) 编辑
摘要:For data class, you can get 'copy' method, and also destructing: data class Customer (val name: String, val address: String, var age: Int) { // if we 阅读全文
posted @ 2020-10-27 17:04 Zhentiw 阅读(84) 评论(0) 推荐(0) 编辑
摘要:// Shorter version class AnotherAlternativeCustomer (val name: String,var age: Int, val address: String = "") { var approvered: Boolean = false set(va 阅读全文
posted @ 2020-10-27 16:49 Zhentiw 阅读(102) 评论(0) 推荐(0) 编辑
摘要:package com.rsk class Customer (val name: String, val address: String, var age: Int) { // if we don't want to pass in the address constructor(name: St 阅读全文
posted @ 2020-10-27 16:42 Zhentiw 阅读(124) 评论(0) 推荐(0) 编辑
摘要:val randomNumber = Random().nextInt(3) if (randomNumber is BigDecimal) { result = result.add(BigDecimal(36)) } If you use type check, then 'result' is 阅读全文
posted @ 2020-10-26 18:36 Zhentiw 阅读(63) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示