ComputerCraft
ComputerCraft copied to clipboard
Use an interface instead of method reflection to call the API
This makes it easier to verify at compile time that API methods are valid. I also think it makes the API code substantially easier to read, but that may just be me.
I also think it makes the API code substantially easier to read, but that may just be me.
Definitely a much better way to do it! Though if ComputerCraft is using Java 8 then it could be made a little cleaner with Optional
s.
Though if ComputerCraft is using Java 8 then it could be made a little cleaner with Optionals.
It could be made even cleaner on top of that using Guava's Suppliers.memoize
(Minecraft/forge already has Guava as a dependency, right?)
e.g. write a supplier to get an optional containing the API impl, memoize it with Guava, and then just use apiSupplier.get().ifPresent(...)