Hacker News new | past | comments | ask | show | jobs | submit login

>This irks me too. It's been a while but I believe the workaround is just to define your own (checked) FunctionE, SupplierE, ConsumerE functional interfaces. But maybe that causes other problems I've forgotten.

You can do that, but you need to do it for every exception type ): I'd love it if Java had templated exceptions.

>> the stupid distinction between primitive types and Objects

One of the slowest things I found out about C# was floats being objects and `a < b` (or something similar) being a stack about 7 levels deep.




> You can do that, but you need to do it for every exception type ): I'd love it if Java had templated exceptions.

It does have them. You can write an interface with a type parameter `<E extends Throwable>` and declare functions inside it with `throws E`


You can do this, but it's not ideal. A function can list multiple exceptions in its throws clause, which share no common type except Throwable, but this combination of exception types can't be represented by a single type parameter (except for the common base type). So in a lot of cases, you lose information about the specific exceptions your function can throw, which limits the value of using checked exceptions.


> One of the slowest things I found out about C# was floats being objects

Floats are value types not objects: https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...

Maybe you we're dealing with floats that had been boxed?


They were probably boxed yeah, we were dealing with unity physics stuff and that's what the benchmarks showed.


That's right, I would run into even bigger performance issues if I used Integer/Long/Double/etc everywhere instead of the primitive types. The problem is not that primitive types are not object, but rather, that generic code will only accept objects and not primitive types.


So don't use generic code in critical inner loops.


The other alternative is to use the error monad in combination with railroad style programming. Of course you also want infix operators like (>>), (>>?) aso.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: