r/programming • • Apr 16 '21

Java is criminally underhyped

https://jackson.sh/posts/2021-04-java-underrated/
41 Upvotes

220 comments sorted by

View all comments

Show parent comments

2

u/AdministrationWaste7 Apr 16 '21

Well this is for manipulating images.

im confused your initial example was simple addition.

so maybe i should reword my question

can you provide a use case where something like this should be applied generically ?

as far as i understand numeric types have little quirks that make this annoying to deal with. so why should it be generic?

also it really doesn't take much effort to implement this yourself.

If you start making interfaces I'm worried about the performance.

when done right the performance hit due to interfaces should be neglible.

Then you have functions to process the image data, but they can work for any size of data and I'd like to just pass an array of any type and be done with it (using generics) but that doesn't work.

i feel like a better answer to this would be something like overloading.

2

u/meneldal2 Apr 16 '21

Yeah I could do overloading, but then I'm literally copy pasting the same function five times with research and replace on types. That's really not ideal.

I just want "generic over any numeric type". Remove the need for overloading something that is trivial to do.

2

u/AdministrationWaste7 Apr 16 '21

I just want "generic over any numeric type". Remove the need for overloading something that is trivial to do.

well its not really trivial.

for example in a generic Add method.

what do you do if you pass in a byte?

1

u/meneldal2 Apr 16 '21

Well it can change them into shorts for the intermediate calculations then I can cast it back to a byte if I want. Or just make it return a byte anyway in this case.

I'd love to have compile time generics for that (with compile time reflection), but should I really have to use C++CLI for this?

→ More replies (0)