Hello. Is there a way (contracts?), or will there ever be a way to do the following?
- mark a function as side-effect-free, so that the compiler can warn if we call the function and do nothing with what it returns?
- mark a class (I’m thinking of a JPA entity here) as only usable in a single thread, so that instance variables which have been checked as not null do not need to be used with
Sorry if that has been asked before. It’s been a long time I haven’t been here 🙂
And the second one: it's not even about threads, what if you call a function that happens to be able to access the instance and it sets a field to
02/19/2019, 3:59 PM
Thanks. Upvoted! You’re right about the second case of course. I guess the compiler could be able to check that, too, but I agree it’s probably not a good idea, since the code would break as soon as the object is used between the null check and the usage of the variable. Thanks again @karelpeeters