Skip to content

thomasdarimont/java-anonymous-types

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

java-anonymous-types

Example of how to create anonymous types in java, using intersection casts

with((Anon & Quacks & Waddles) i -> i, ducklike -> {
    ducklike.quack();
    ducklike.waddle();
});

You can also enhance existing types with List with new methods like map

interface Mappable<T> extends DelegatesTo<List<T>> {
    default <R> List<R> map(Function<T,R> mapper) {
        return delegate().stream().map(mapper).collect(Collectors.toList());
    }
}

with((ForwardingList<String> & Mappable<String>)() -> stringList, list -> {
    list.map(String::toUpperCase).forEach(System.out::println);
});

About

Anonymous types in java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%