Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 1.1 KB

README.md

File metadata and controls

55 lines (39 loc) · 1.1 KB

common

License GPLv2.

Duck typing for Java

This is a duck typing implementation based on reflection and dynamic proxies with force methods access. Perhaps it can be used as a wrapper for reflect.

Examples

Call with parameter contravariant.

class Foo {
    void run() {
        println("I'm running")
    }
    void print(String msg) {
        println(msg)
    }
}

Foo foo = new Foo()
Runnable runnable = Types.asType(foo, Runnable.class)
runnable.run()// I'm running

Call with method name map.

class Foo {
    void run() {
        println("I'm running")
    }
}

Foo foo = new Foo()
Types.desc(Foo.class).map("run", Closeable.class, "close")
Types.asType(foo, Closeable.class).close()// I'm running

Compiled PlaceholderAPI string

10x faster than PlaceholderAPI.setPlaceholder(Player, String)

Examples

import com.mengcraft.util.CompiledStr
import org.bukkit.Bukkit

def compiled = new CompiledStr("My name is %player_name%")

println compiled.apply(Bukkit.getPlayerExact("HIM")) // My name is HIM