12

Am I going crazy or am I just retarded?

Comments
  • 2
    Please ignore the 2cool4u coding style
  • 10
    You're abusing the ternarys and it makes them sad :<<

    You're not supposed to do assignment inside of the ternarys expression. The assignment is supposed to be the result of it
  • 2
    What ur trying to do is:

    return singleton != null ? null : new StaticFun();

    You cannot assign inside an inline statement.
  • 0
    @irene I'm supposed to return an instance on the first call and null after that. I know it makes no sense, don't ask me
  • 0
    @creskendoll Why though? Assignment is a normal operator and evaluates to the right hand value. That's how 'a = b = 1;' works
  • 0
    @creskendoll What I'm trying to do is what the code says. My problem is the weird ass syntax error for no reason
  • 2
    I figured it out. It's a parse error because assignment has a lower precendence than than the ternary operator in java. Mystery solved I guess
  • 0
    @12bitfloat never seen such a thing. Glad for you 😛
  • 0
    Whatever requirements that made this code necessary might be the most retarded thing I’ve seen. Beautiful solution. Not huge on java but would getter that sets value to null before get returns work? Then you might be able to avoid Singleton. I hate singletons :/
  • 1
    @NSGangster You can just do a normal if else, I just like to fuck with the people having to correct the homework
  • 1
    @12bitfloat it was painful.
    imma have one more trauma now D:
  • 0
    A boolean flag would suffice then :) now that static instance will never be garbage-collected. That's how memleaks are made :)
  • 0
    this code gives me cancer
  • 1
    @12bitfloat don't 👏 assign 👏 in 👏 ternarys 👏 my dude. Ternarys are not control flow they are expressions
  • 0
    If you don't understand ternary operators - don't use them. It's not a shame at all plus you logical expression is quite to complicated to be readable in a ternary expression anyway
  • 0
    @c64forthewin I *do* understand them. The code works, it's just a parse error my dude. Not that the code isn't ugly or overly complex. I just don't like how everybody assumes I'm a noob when they don't understand themselves what I'm doing in the first place
  • 0
    @12bitfloat If you understand them why do you use them incorrectly tho?
  • 0
    @inaba It works perfectly as designed I just messed up the precendence
  • 0
    @12bitfloat I said dick all about it not working so lets take it again and slowly this time.

    Ternarys are expressions which means they return something. You use whatever they return in a variable and do with it whatever you want. You are not supposed to use them like ifs because they not statements. You're not using them as designed use an if statement instead because they're designed to do what you're trying to do
  • 0
    @inaba It's not supposed to be nice code. I just wanted to do it because it works and I want to fuck with the profs, it ain't that hard to understand
Add Comment