5 ms·
It definitely is common with generics, it happens all the time. Here's some production code I've worked on recently: new TypeReference<FooResponseCollecti
by sytringy05 7y ago
It definitely is common with generics, it happens all the time. Here's some production code I've worked on recently:
new TypeReference<FooResponseCollectionResource<MemberUpdate>>(){})
I like generics, but I don't love this sort of thing and it's not even a mis-use of them
- je42 7y agowhat's the alternative ? using an "untyped" variable ? but then you loose type checking and some people don't like to loose type checking...
- KptMarchewa 7y agoDo not use patterns that require you to write code like that.
- KirinDave 7y agoOr use type aliases that are helpful.
- ratww 7y agoThat's the answer for me. The problem in those cases always the abuse of often obsolete OOP patterns and misnamed classes.
- Thiez 7y agoYou never have cases where you have a list of lists? Or do you introduce a pointless wrapper type for the inner lists to "hide" the generics?
- pjmlp 7y agoMany languages do support type alias. In C# you would do using NiceType = TypeReference<FooResponseCollectionResource<MemberUpdate>> // .... new NiceType ()
- ratww 7y agoMy point was that the commonly mocked VisitorObserverFacadeFactoryFactory Java idiom doesn't normally use generics at all. Of course you can mix generics with terribly named classes and OOP patterns, but that's hardly a problem with generics themselves.