That's... exactly the kind of thing a type system is intended to stop you from doing.
I'm not saying it's a bad idea, just that it's not really a core application of type systems in real-world programming practice.
You don't need too advanced of a type system to implement what you're talking about. With the caveat that doing it in Java would make the code tedious to write ;-).