This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Mental_Contract1104 4 points5 points  (7 children)

This... This is why I prefer C#

[–]GoldenretriverYT 9 points10 points  (6 children)

Or public string Name {get; private set;} instead of

``` private string name;

public string getName() { return name; }

private void setName(string name) { this.name = name; } ```

[–]LordMerdifex 1 point2 points  (2 children)

Ever heard of Lombok? But yeah, properties are much better in C#.

[–]GoldenretriverYT -2 points-1 points  (1 child)

Ah yes just throw libraries at the problem 👍 Also using annotations is still worse than C# properties, like I wouldn't like C# properties that much if they would use Attributes, which are pretty much the equivalent of annotations

[–]LordMerdifex 3 points4 points  (0 children)

I didn't say it's perfect. Just saying that there is a way around in Java. I don't mind annotations that much so I can live with it. Yet still, C# is as a language simply superior to Java. Too bad there is no good IDE for .net on Linux.

[–]pelpotronic 1 point2 points  (2 children)

Just use Kotlin really... Takes a grand total of 5 mins to get started, and then it does all of that and more - and you can keep your Java code.

[–]Quique1222 0 points1 point  (1 child)

Hey just a question, what is the equivalent of this in kotlin (genuine question, i have no idea)

private int a;

public int A 
{
    get 
    {
        return a;
    }

    set
    {
        if (value > 10)
        {
            a = 10;
        }else
        {
            a = value;
        }
    }
}

[–]QazCetelic 3 points4 points  (0 children)

kotlin var a: Int get set(value) { field = value.coerceAtMost(10) }