Why don’t primitive Stream have collect(Collector)?

We did in fact prototype some Collector.OfXxx specializations. What we found — in addition to the obvious annoyance of more specialized types — was that this was not really very useful without having a full complement of primitive-specialized collections (like Trove does, or GS-Collections, but which the JDK does not have). Without an IntArrayList, for … Read more

Using annotation to ensure that value returned by method is not discarded

You could also check out jsr305. It defines a @CheckReturnValue annotation: import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import javax.annotation.meta.When; @Documented @Target( { ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE, ElementType.PACKAGE }) @Retention(RetentionPolicy.RUNTIME) public @interface CheckReturnValue { When when() default When.ALWAYS; } It’s compatible with findbugs and generates a warning when someone forgets to handle the … Read more

Should I prefer private member functions, or functions in an unnamed namespace? [duplicate]

In the semi large projects where I usually work (more than 2 million lines of code) I would ban private class functions if I could. The reason being that a private class function is private but yet it’s visible in the header file. This means if I change the signature (or the comment) in anyway … Read more

When should I use pointers instead of references in API-design?

Use references wherever you can, and pointers wherever you must. Avoid pointers until you can’t. The reason is that pointers make things harder to follow/read, less safe and far more dangerous manipulations than any other constructs. So the rule of thumb is to use pointers only if there is no other choice. For example, returning … Read more

What is the standard for formatting currency values in JSON?

I don’t know if it’s the best solution, but what I’m trying now is to just pass values as strings unformatted except for a decimal point, like so: “amount”: “1234.56” The app could easily parse that (and convert it to double, BigDecimal, int, or whatever method the app developer feels best for floating-point arithmetic). The … Read more

find-or-create idiom in REST API design?

I believe the “correct” RESTful way to do this would be : GET /user?name=bob 200: entity contains user 404: entity does not exist, so POST /user { “name” : “bob” } 303: GET /user?name=bob 200: entity contains user I’m also a big fan of the Post-Redirect-Get pattern, which would entail the server sending a redirect … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)