Mimicking Java's Type Erasure

Superstar64 Hexagonalstar64 at gmail.com
Mon Nov 4 00:16:53 UTC 2019


Consider the following Java code.
--
import java.util.function.Function;
public class Main{

     //basic Rank2 type
     static interface Stringer{
         <A> String show(Function<A,String> type, A that);
     }

     static class Say implements Stringer {
         public <A> String show(Function<A,String> type, A that){
             return type.apply(that);
         }
     }

     static class Shout implements Stringer {
         public <A> String show(Function<A,String> type, A that){
             return type.apply(that) + "!!!";
         }
     }

}
--
This uses Java's generics' type erasure to create a basic rank 2 
type.
What are some clean ways to implement something similar in D, in 
a type safe manner if preferable?


More information about the Digitalmars-d-learn mailing list