File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
core-kotlin-modules/core-kotlin-10/src/main
kotlin/com/baeldung/access_private_members_from_extension_func Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .baeldung ;
2
+
3
+ public class StringWrapper {
4
+ private final String source ;
5
+
6
+ public StringWrapper (String source ) {
7
+ this .source = source ;
8
+ }
9
+
10
+ public boolean containsIgnoreCase (String other ) {
11
+ if (source == null ) {
12
+ return false ;
13
+ }
14
+
15
+ return source .toLowerCase ().contains (other .toLowerCase ());
16
+ }
17
+
18
+ public String getSource () {
19
+ return source ;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ package com.baeldung.access_private_members_from_extension_func
2
+
3
+ class Main {
4
+ fun String?.containsIgnoreCase (target : String ) : Boolean {
5
+ if (this == null ) {
6
+ return false
7
+ }
8
+
9
+ val loadedClass = String ::class
10
+ val valueField = loadedClass.java.getDeclaredField(" value" )
11
+ valueField?.isAccessible = true
12
+ val actualValue = valueField?.get(this ) as ? ByteArray
13
+
14
+ println (actualValue?.contentToString())
15
+
16
+ return this .lowercase().contains(target.lowercase())
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments