News for hackers. Stuff that matters.
Re:Java: Missing Features by lolklyn on Wednesday November 25, 2015 @05:27PM (#10630166)
What I would love to come over from C# is:

* Auto-Properties - Get rid of all those ugle getters and setters cluttering up POJOs

* Object and Collection Initialisers - https://msdn.microsoft.com/en-us/library/bb384062.aspx

Re:Java: Missing Features by jonathankoren on Thursday November 26, 2015 @02:11AM (#10631705)
If there's no logic in the getter and setters, just make the properties public.
Re:Java: Missing Features by Retra on Thursday November 26, 2015 @02:20AM (#10631727)
That works until you want to add logic without breaking existing interfaces.
Re:Java: Missing Features by masklinn on Thursday November 26, 2015 @02:27AM (#10631752)
Or until you need to use them in beans and the like.
Re:Java: Missing Features by tajen on Thursday November 26, 2015 @02:45AM (#10631802)
Play!Framework 2 for Java is awesome in this matter. You write public members, but at compilation it transforms them into private members with getters and setters (if not final). It means if you write the setter, it overrides the default one.
Re:Java: Missing Features by kuschku on Thursday November 26, 2015 @02:51AM (#10631815)
Lombok does the same ;)
Re:Java: Missing Features by jinst8gmi on Thursday November 26, 2015 @04:30AM (#10632116)
But then you're using Lombok...
Re:Java: Missing Features by dfullarton on Thursday November 26, 2015 @07:32AM (#10632663)
Can you clarify? I've heard similar negative feelings from devs. What's wrong with lombok?
Re:Java: Missing Features by ossreality on Thursday November 26, 2015 @02:17AM (#10631720)
Huh? Then they're just fields and not properties, maybe I'm misunderstanding what you're trying to say. And there are numerous reasons that Properties are preferable to Fields.

Unless someone else can help me, I think this is really bad advice for a C# developer.

Re:Java: Missing Features by jonathankoren on Saturday November 28, 2015 @01:17AM (#10640233)
>Huh? Then they're just fields and not properties

Nomenclature schmomenclature.

They're variables with object scope.

Re:Java: Missing Features by mbfg on Wednesday November 25, 2015 @08:36PM (#10630836)
might want to checkout lombok. https://projectlombok.org/
Re:Java: Missing Features by josecflk3 on Thursday November 26, 2015 @01:25AM (#10631581)
Just keep in mind that some of the features are a bit iffy. If you use their vals IntelliJ will syntax highlight it as an error in red for the simple reason that it's non-compliant with the Java language spec. Also, you'll usually need a new version on Lombok every time a new version of Java comes out, otherwise what used to compile with the previous java version will no longer compile. If you use the auto constructor you're going to have fun finding usages since there's nothing to click on, and changing the order of fields in your class will silently change the ordering of parameters in your constructor - double the fun of the fields are of the same type. You'll also be left wondering why you went to all the trouble of adding dodgy language extensions instead of just using a language which provides those features anyway. That and your code (subjectively) looks really ugly plastered with annotations everywhere. Some people like Lombok, just make sure it's a choice you make going in with your eyes open.
Re:Java: Missing Features by scalesolved on Thursday November 26, 2015 @04:39AM (#10632154)
We use Lombok heavily where I work, on > 5 projects and have yet to run into any problems like you describe. Everyone use IntelliJ apart from myself and haven't heard any issues with using 'val'. We started off just using it in tests but it's now spread throughout the code base, I can't imagine going back to pre Java 8 sans Lombok.
Re:Java: Missing Features by ks on Thursday November 26, 2015 @04:52AM (#10632199)
> If you use their vals IntelliJ will syntax highlight it as an error in red for the simple reason that it's non-compliant with the Java language spec.

There's a free plugin that adds Lombok support to Intellij. You will be able to use getters/setters/builders etc. as if they were compiled.

Re:Java: Missing Features by josecflk3 on Thursday November 26, 2015 @05:01AM (#10632236)
Builders etc. work fine, it's the vals that are permanently underlined in red, even with the plug in. It compiles OK with vals, but still highlights it as an error in red in the editor.
Re:Java: Missing Features by jinst8gmi on Thursday November 26, 2015 @02:49AM (#10631810)
True. I've seen multiple teams putting a lot of effort into removing Lombok from their codebases after all the trouble it caused.
Re:Java: Missing Features by ionised on Thursday November 26, 2015 @11:01AM (#10633480)
Lombok's val is the only thing I don't use in the Lombok library.
Re:Java: Missing Features by kbenson on Thursday November 26, 2015 @12:42AM (#10631463)
Isn't that just a boilerplate generator? I think the point is to have sane defaults and shorthand for common tasks so boilerplate generation isn't needed.
Re:Java: Missing Features by dikaiosune on Thursday November 26, 2015 @12:48AM (#10631476)
If I'm not mistaken, Lombok generates the boilerplate at the bytecode level, not at the source code level. Which makes it much more like a language feature, and while I haven't used it extensively seems like a decent library solution to what is normally considered a language problem.
Re:Java: Missing Features by nerdwaller on Thursday November 26, 2015 @01:20AM (#10631568)
I just stumbled on this today (before coming here), looks really nice to rid some boilerplate. Regardless for some reason I still love Java...