File tree Expand file tree Collapse file tree 9 files changed +174
-2
lines changed
open_properties_inheritance Expand file tree Collapse file tree 9 files changed +174
-2
lines changed Original file line number Diff line number Diff line change 2
2
<project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3
3
xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
4
4
5
- <modelVersion >4.0.0</modelVersion >
5
+ <modelVersion >4.0.0</modelVersion >
6
6
<artifactId >k2-compiler</artifactId >
7
7
<name >k2-compiler</name >
8
8
14
14
15
15
<properties >
16
16
<kotlin .version>2.0.0</kotlin .version>
17
+ <kotlin-stdlib-jdk8 .version>2.0.0</kotlin-stdlib-jdk8 .version>
17
18
</properties >
18
19
20
+ <dependencies >
21
+ <dependency >
22
+ <groupId >org.jetbrains</groupId >
23
+ <artifactId >annotations</artifactId >
24
+ <version >24.1.0</version >
25
+ </dependency >
26
+ </dependencies >
27
+
28
+ <build >
29
+ <sourceDirectory >src/main/kotlin</sourceDirectory >
30
+ <testSourceDirectory >src/test/kotlin</testSourceDirectory >
31
+ <plugins >
32
+ <plugin >
33
+ <groupId >org.codehaus.mojo</groupId >
34
+ <artifactId >build-helper-maven-plugin</artifactId >
35
+ <version >3.2.0</version >
36
+ <executions >
37
+ <execution >
38
+ <phase >generate-sources</phase >
39
+ <goals >
40
+ <goal >add-source</goal >
41
+ </goals >
42
+ <configuration >
43
+ <sources >
44
+ <source >src/main/java</source >
45
+ </sources >
46
+ </configuration >
47
+ </execution >
48
+ </executions >
49
+ </plugin >
50
+ <plugin >
51
+ <groupId >org.jetbrains.kotlin</groupId >
52
+ <artifactId >kotlin-maven-plugin</artifactId >
53
+ <version >${kotlin-stdlib-jdk8.version} </version >
54
+ <executions >
55
+ <execution >
56
+ <id >compile</id >
57
+ <phase >compile</phase >
58
+ <goals >
59
+ <goal >compile</goal >
60
+ </goals >
61
+ </execution >
62
+ <execution >
63
+ <id >test-compile</id >
64
+ <phase >test-compile</phase >
65
+ <goals >
66
+ <goal >test-compile</goal >
67
+ </goals >
68
+ </execution >
69
+ </executions >
70
+ </plugin >
71
+ <plugin >
72
+ <groupId >org.apache.maven.plugins</groupId >
73
+ <artifactId >maven-compiler-plugin</artifactId >
74
+ <configuration >
75
+ <source >11</source >
76
+ <target >11</target >
77
+ </configuration >
78
+ </plugin >
79
+ </plugins >
80
+ </build >
19
81
</project >
Original file line number Diff line number Diff line change
1
+ package arrays_nullability ;
2
+
3
+ import org .jetbrains .annotations .Nullable ;
4
+
5
+ public class StringUtils {
6
+
7
+ public static @ Nullable String fromCharArray (char [] s ) {
8
+ if (s == null || s .length == 0 ) return null ;
9
+
10
+ return new String (s );
11
+ }
12
+
13
+ public static char @ Nullable [] toCharArray (String s ) {
14
+ if (s == null ) return null ;
15
+
16
+ return s .toCharArray ();
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ package generics ;
2
+
3
+ public class Box <E > {
4
+
5
+ private E value ;
6
+
7
+ public E getValue () {
8
+ return value ;
9
+ }
10
+
11
+ public void setValue (E value ) {
12
+ this .value = value ;
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ package resolution ;
2
+
3
+ public class AbstractEntity {
4
+ public String type = "ABSTRACT_TYPE" ;
5
+ public String status = "ABSTRACT_STATUS" ;
6
+ }
Original file line number Diff line number Diff line change
1
+ package arrays_nullability
2
+
3
+ fun main () {
4
+ val resultString : String? = StringUtils .fromCharArray(null ) // Corret type should be String?
5
+ val array : CharArray = StringUtils .toCharArray(null ) // That compiles fine in K1
6
+ println (array[0 ]) // NPE
7
+ }
Original file line number Diff line number Diff line change
1
+ package generics
2
+
3
+ import generics.Box
4
+
5
+ fun execute (list : MutableList <* >, element : Any ) {
6
+ list.add(element)
7
+ }
8
+
9
+ fun explicitSetter () {
10
+ val box = Box <String >()
11
+ val tmpBox: Box <* > = box
12
+ tmpBox.setValue (12 ) // Compile Error! Thats unsafe!
13
+ val myValue : String? = box.value
14
+ }
15
+
16
+ fun syntheticSetter () {
17
+ val box = Box <String >()
18
+ val tmpBox : Box <* > = box
19
+ tmpBox.value = 12 // That compiles!
20
+ val foo : String? = box.value // And here we fail with ClassCastException
21
+ }
22
+
23
+ fun syntheticSetter_inVariance () {
24
+ val box = Box <String >()
25
+ val tmpBox : Box <in String > = box
26
+ tmpBox.value = 12 // Wow, thats a trap again!
27
+ val foo : String? = box.value // Blast! ClassCastException
28
+ }
29
+
Original file line number Diff line number Diff line change
1
+ import java.time.Instant
2
+
3
+ // Does not compile in Both old and K2 Kotlin compilers
4
+ // open class BaseEntity {
5
+ // open val points: Int
6
+ // open var pages: Long?
7
+ //
8
+ // init {
9
+ // points = 1
10
+ // pages = 12
11
+ // }
12
+ // }
13
+
14
+ open class BaseEntity {
15
+ open val points: Int = 1
16
+ open var pages: Long? = 12
17
+ }
18
+
19
+ open class WithLateinit {
20
+ open lateinit var point: Instant
21
+ }
Original file line number Diff line number Diff line change
1
+ package resolution
2
+
3
+ class AbstractEntitySubclass (val type : String ) : AbstractEntity() {
4
+
5
+ val status: String
6
+ get() = " CONCRETE_STATUS"
7
+ }
8
+
9
+ fun main () {
10
+ val sublcass = AbstractEntitySubclass (" CONCRETE_TYPE" )
11
+ println (sublcass.type)
12
+ println (sublcass.status)
13
+ }
Original file line number Diff line number Diff line change 490
490
<module >core-kotlin-companion</module >
491
491
<module >core-kotlin-modules</module >
492
492
<!-- <module>gradle-kotlin-dsl</module> --> <!-- not a Maven module -->
493
+ <!-- <module>k2-kotlin</module> --> <!-- Contains a lot of examples where code intentionally does not compile, by design -->
493
494
<!-- <module>kotlin-jee</module> --> <!-- Can't upgrade this project. Arquillian not maintained anymore.-->
494
- <module >k2-compiler</module >
495
+ <!-- < module>k2-compiler</module> --> <!-- Contains a lot of examples where code intentionally does not compile, by design -- >
495
496
<module >koin-guide</module >
496
497
<module >kotlin-kotest</module >
497
498
<module >kotlin-apache-kafka</module >
571
572
<module >core-kotlin-companion</module >
572
573
<module >core-kotlin-modules</module >
573
574
<!-- <module>gradle-kotlin-dsl</module> --> <!-- not a Maven module -->
575
+ <!-- <module>k2-kotlin</module> --> <!-- Contains a lot of examples where code intentionally does not compile, by design -->
574
576
<!-- <module>kotlin-jee</module> --> <!-- Can't upgrade this project. Arquillian not maintained anymore.-->
575
577
<module >k2-compiler</module >
576
578
<module >koin-guide</module >
You can’t perform that action at this time.
0 commit comments