본문 바로가기

Back-End (web)50

[Kotlin] Collection - all, any, count, find All collection 의 원소들이 모두 조건을 만족하는지 println(""" 모든 원소가 조건을 만족하는지 홀수인지 [1, 3, 5, 7] : ${listOf(1, 3, 5, 7).all{ it%2 == 1 }} 홀수인지 [1, 3, 5, 7, 8] : ${listOf(1, 3, 5, 7, 8).all{ it%2 == 1 }} """.trimIndent()) 모든 원소가 조건을 만족하는지 홀수인지 [1, 3, 5, 7] : true 홀수인지 [1, 3, 5, 7, 8] : false Any collection 안에 조건을 만족하는 원소가 존재하는지 println(""" 홀수가 있는지 [1, 3, 5, 6] : ${listOf(1, 3, 5, 6).any{ it%2 == 0 }} [1, 3, 5] .. 2021. 12. 29.
[Kotlin] Sealed Class Sealed Class 의 구현체들은 컴파일 시간에 알 수 있습니다. sealed class SealClass { abstract val no: Int } class A: SealClass() { override val no: Int = 12 } fun main() { // Sealed types cannot be instantiated // val sealClass = SealClass() val a = A() .also { println(it.no) } } sealed class는 abstract 멤버를 가질 수 있습니다. sealed class는 그자체로 객체가 될 수 없습니다. (Sealed types cannot be instantiated 에러 뱉음) internal class SealedCl.. 2021. 12. 28.
[Spring] 배치 실행 시 'BATCH_JOB_INSTANCE.PRIMARY' 중복 에러 mysql 서버에 스프링 배치를 위한 테이블을 기존 다른 서버에 있던 테이블들의 create 쿼리를 따와서 해당 쿼리로 테이블들을 생성 후 배치를 실행해봤다. 데이터가 아무것도 없었던 첫 번째 실행의 경우엔 정상적으로 실행되나 두 번째 실행부터 아래와 같은 에러가 발생했다. java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '0' for key 'BATCH_JOB_INSTANCE.PRIMARY' 그래서 생성했던 배치 관련 테이블을 다 삭제하고 스프링에서 제공해주는 쿼리로 테이블을 생성했다. spring batch core 4.3.3 version 기준, schema-mysql.sql 파일에 있는 쿼리이다. (링크) use '데이터베이스.. 2021. 11. 19.
[Spring][Kotlin] Main class name has not been configured and it could not be resolved Execution failed for task ':bootRun'. > Failed to calculate the value of task ':bootRun' property 'mainClass'. > Main class name has not been configured and it could not be resolved 어플리케이션 띄울때, main class를 못찾는다고 한다. // build.gradle.kts springBoot { mainClass.set("com.withhamit.chatting.ChattingApplicationKt") } mainClass 위치를 명시적으로 지정해준다. 코틀린으로 작성한 경우 자바로 컴파일될때 파일명에 Kt가 붙기 때문에 ChattingApplication.. 2021. 6. 26.
[Gradle][Error] Cannot lock execution history cache ... as it has already been locked by this process. Cannot lock execution history cache ([git 경로]\chatting-server\.gradle\6.8\executionHistory) as it has already been locked by this process. 어플리케이션 띄운 후 종료하고 다시 띄웠을 때 위와 같은 에러가 발생했다. github 경로에 있는 .gradle 파일이 문제라는 식으로 보이는데 global .gradle 폴더(C:\Users\[사용자이름]\.gradle)의 문제이다. global .gradle 폴더를 삭제해줘도 되고 // gradle.properties org.gradle.caching=false gradle 캐싱을 사용하지 않는다는 설정을 넣어서 돌려도 해결된다. 항상 캐싱을 사용안하면 .. 2021. 6. 26.
[kotlin] property, backing field kotlin에서는 필드가 아닌 프로퍼티를 정의한다고 합니다. val name: String = "" // 불변 var name: String // 가변 프로퍼티는 var, val로 선언할 수 있습니다. var는 가변변수로 값을 변경할 수 있습니다. val는 불변변수로 값을 변경할 수 없습니다. java에서는 getter, setter를 보통 get필드이름. set필드이름 이라는 함수명으로 개발자가 직접 만들어 줬어야 합니다. kotlin에서는 프로퍼티에 getter, setter를 정의할 수 있습니다. data class MyTest ( val name: String ) { val fullName: String get() = "full $name" var diffName: String = "" get().. 2021. 2. 4.