File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
core-kotlin-modules/core-kotlin-lang-4/src
main/java/com/baeldung/backticks
test/kotlin/com/baeldung/backticks Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .baeldung .backticks ;
2
+
3
+ public class BackTickUsage {
4
+ public boolean is () {
5
+ return true ;
6
+ }
7
+ }
Original file line number Diff line number Diff line change
1
+ package com.baeldung.backticks
2
+
3
+ import org.junit.jupiter.api.Test
4
+ import kotlin.test.assertEquals
5
+ import kotlin.test.assertTrue
6
+
7
+ class BackticksUnitTest {
8
+ @Test
9
+ fun `use backticks to escape reserved keywords` () {
10
+ val `class ` = " Hello"
11
+ assertEquals(" Hello" , `class `)
12
+ }
13
+
14
+ @Test
15
+ fun `use backticks to allow special characters in identifier` () {
16
+ val `special Name $and @` = " Hello"
17
+ assertEquals(" Hello" , `special Name $and @`)
18
+ }
19
+
20
+ @Test
21
+ fun `use backticks to refer to Java method that is a keyword in Kotlin` () {
22
+ val backTickUsageJavaClass = BackTickUsage ()
23
+ assertTrue(backTickUsageJavaClass.`is `())
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments