DEV Community

loading...

Kotlin – Java Static Method equivalent in Kotlin

loizenai profile image loizenai ・1 min read

https://grokonez.com/kotlin/kotlin-java-static-method-equivalent-kotlin

Kotlin – Java Static Method equivalent in Kotlin

This tutorial shows you a way to represent Java static method in Kotlin using Object Expression.

I. Technology

  • Java 1.8
  • Kotlin 1.1.2

    II. Practice

    1. Java static Classes and Methods

    
    public class Foo {
    
    public static String exe() {
        return "grokonez.com";
    }
    
    public static String upperCase(String s) {
        return s.toUpperCase();
    }
    
    public static class Bar {
    
        public static String bar() {
            return "Bar";
        }
    }
    
    public static class Num {
    
        public static Integer doubleInt(Integer i) {
            return new Integer(i.intValue() * 2);
        }
    }
    }

    2. Equivalent in Kotlin

    Using Kotlin Object Expression, we can make "static" Equivalent:

More at:

https://grokonez.com/kotlin/kotlin-java-static-method-equivalent-kotlin

Discussion (0)

pic
Editor guide