115
you are viewing a single comment's thread
view the rest of the comments
[-] Nighed@feddit.uk 2 points 4 days ago* (last edited 4 days ago)

It could be an OUT variable? (Does java have them?)

[-] Starfighter@discuss.tchncs.de 2 points 4 days ago

Not as far as I'm aware of. You can kinda fake it with references like you would in C++.

With all the missing context it would also be possible that the author is trying to track invalid whatevers and the invalid flag is actually wanted state.

[-] addie@feddit.uk 1 points 4 days ago

In Java, all objects are passed to methods 'by reference', and there is no way to mark them as immutable. So strictly speaking, they're all 'out variables'. This is the cause of a lot of mistakes in Java, where you eg. pass a list to a method, which then mutates it in some way. That will change the original that the caller passed in, which is normally unintended and may break class invariants. So Java tends to have an absurd number of 'safety copies' and immutable wrappers of collections.

I'd probably describe the inability to mark things immutable as the main problem with Java. The golden rule of concurrency is that if you share mutable state, you must use an appropriate synchronisation primitive. It's not easy to mark things immutable (final doesn't do what const does in C++) and although you can make class internals private if you like, the junior devs at my work will come along and add accessor methods.

tl:dr; yes it does. Passing an AtomicBoolean as a method argument will do as a built-in 'mutable object that holds a boolean and can be checked by caller', although it'll be slower than your own custom object since it does sync you won't need.

[-] Nighed@feddit.uk 2 points 3 days ago* (last edited 3 days ago)

I'm from C# that has the following for your list example:

// If you add an item to this list, it will effect usages outside. You can't reassign it though.
public void Example(List<string> exampleParam)

//Full passing by ref, if you re-assign it to a complete new object, outside usages will be effected
public void Example(ref List<string> exampleParam)

//Output only, this acts as if the method assigned a variable named exampleParam. 
public void Example(out List<string> exampleParam)

this post was submitted on 01 Oct 2025
115 points (100.0% liked)

Software Gore

6141 readers
133 users here now

Welcome to /c/SoftwareGore!


This is a community where you can poke fun at nasty software. This community is your go-to destination to look at the most cringe-worthy and facepalm-inducing moments of software gone wrong. Whether it's a user interface that defies all logic, a crash that leaves you in disbelief, silly bugs or glitches that make you go crazy, or an error message that feels like it was written by an unpaid intern, this is the place to see them all!

Remember to read the rules before you make a post or comment!


Community Rules - Click to expand


These rules are subject to change at any time with or without prior notice. (last updated: 7th December 2023 - Introduction of Rule 11 with one sub-rule prohibiting posting of AI content)


  1. This community is a part of the Lemmy.world instance. You must follow its Code of Conduct (https://mastodon.world/about).
  2. Please keep all discussions in English. This makes communication and moderation much easier.
  3. Only post content that's appropriate to this community. Inappropriate posts will be removed.
  4. NSFW content of any kind is not allowed in this community.
  5. Do not create duplicate posts or comments. Such duplicated content will be removed. This also includes spamming.
  6. Do not repost media that has already been posted in the last 30 days. Such reposts will be deleted. Non-original content and reposts from external websites are allowed.
  7. Absolutely no discussion regarding politics are allowed. There are plenty of other places to voice your opinions, but fights regarding your political opinion is the last thing needed in this community.
  8. Keep all discussions civil and lighthearted.
    • Do not promote harmful activities.
    • Don't be a bigot.
    • Hate speech, harassment or discrimination based on one's race, ethnicity, gender, sexuality, religion, beliefs or any other identity is strictly disallowed. Everyone is welcome and encouraged to discuss in this community.
  9. The moderators retain the right to remove any post or comment and ban users/bots that do not necessarily violate these rules if deemed necessary.
  10. At last, use common sense. If you think you shouldn't say something to a person in real life, then don't say it here.
  11. Community specific rules:
    • Posts that contain any AI-related content as the main focus (for example: AI “hallucinations”, repeated words or phrases, different than expected responses, etc.) will be removed. (polled)


You should also check out these awesome communities!


founded 2 years ago
MODERATORS