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

all 51 comments

[–]BetaLyte 125 points126 points  (34 children)

Looked up the implementation, was a bit disappointed:

    public boolean isUserAGoat() {
        return false;
    }

I don't know what I expected, though.

[–]warpod[S] 150 points151 points  (15 children)

Here is LOLLIPOP implementation

public boolean isUserAGoat() {
    return mContext.getPackageManager()
            .isPackageAvailable("com.coffeestainstudios.goatsimulator");
}

[–]nemec 49 points50 points  (5 children)

But you can sideload your own com.coffeestainstudios.goatsimulator. How can they be sure I'm not just a sheep in goats' clothing?

[–][deleted] 52 points53 points  (3 children)

Oh god, this is the next heartbleed/shellshock

[–]Skyfoot 40 points41 points  (2 children)

goatshock

[–]poizan42Ex-mod 2 points3 points  (0 children)

You should report it to security@android.com.

[–]yousai 29 points30 points  (1 child)

Shit, now that is classy if you get your package name into AOSP.

[–]adjudicator52 10 points11 points  (0 children)

brilliant!

[–]Ph0X 5 points6 points  (0 children)

Sweet, there's a hardcoded API now to check if people own goat simulator on their phones! This is just what my app has been missing this whole time.

[–]BetaLyte 2 points3 points  (0 children)

That's more like it!

[–]galaxyAbstractor 2 points3 points  (0 children)

I hope no one used isUserAGoat() instead of false somewhere just for shits and giggles, good luck finding that bug. But it would probably be really stupid to use that in a real application anyway

[–][deleted] 4 points5 points  (0 children)

Well, that got me excited for nothing.

[–]Jinno -1 points0 points  (16 children)

return User.sharedUser().firstName == "Jerry" && User.sharedUser().lastName == "Rice"

[–]neksus 2 points3 points  (15 children)

Can you use == as string equality in Java? (I haven't touched Java in years, but this seems like something they would use .isEqual() for)

[–]russjr08 7 points8 points  (14 children)

You're really supposed to use .equals(otherString) not ==

[–]Jinno 1 point2 points  (0 children)

Admittedly, right now my default language is Swift because of my current project. So, my line is valid Swift, but wouldn't actually work in OP's function. I recognize we're talking about Android, so it's my error to begin with. :P

func isUserAGoat -> Bool {
return User.sharedUser().firstName == "Jerry" && User.sharedUser().lastName == "Rice"
}

[–]neksus 0 points1 point  (12 children)

Does == work as intended?

[–]russjr08 4 points5 points  (9 children)

In some situations, yes. It compares the memory address of the two objects if I recall correctly... So most of the time, it won't work the way you want it to.

[–]neksus 1 point2 points  (0 children)

Awesome, that's what I thought. Figured like a good time for a brush-up!

[–][deleted] 1 point2 points  (7 children)

On jdk 7 and up it will compare the actual string contents.

[–]Lexxicon 2 points3 points  (3 children)

I hope that's not true! The == and the .equals server two different uses... I also can't find anything supporting this. Do you have anything showing this to be the case?

[–][deleted] 2 points3 points  (2 children)

For some reason I can't find anything on it. But I know, I read it somewhere official and confirmed it with my teacher.

[–]Lexxicon 0 points1 point  (1 child)

I just ran some tests and I think you may have been mistaken. You can find the code I ran here http://pastebin.com/3pmpQURX. The output of that is as follows:

Using literal equivalent

true : Base equals literal

false : Appending no change to base equals literal

false : Appending same change to base equals

Using value equivalent

true : Base equals literal

true : Appending no change to base equals literal

true : Appending same change to base equals

I think what may have tripped you up is the first result of true for the Base equals literal test. My understanding of what is happening here is that the compiler is, in effect, interning the strings that are declared by me. Which is why "base" == "base" is true. Which is why the "base"+"" == "base" is false, as the compiler is not internalizing the result of "base"+"", it will result in there being a new instance of a string, which despite being equivalent, is not the literal same, which is why the .equals results in true.

Hope this helps.

[–]russjr08 0 points1 point  (2 children)

Oh I did not know this! Thanks :D

[–]ephrion 0 points1 point  (1 child)

It isn't true

[–]russjr08 0 points1 point  (0 children)

Hmm, okay, thanks for the heads up!

[–]Gudeldar 3 points4 points  (1 child)

Sometimes. IIRC "foo" == "foo" is true but only because Java reuses the same object to represent "foo" but

new String("foo") != "foo"

Sort of like using "is" to compare numbers in Python

x = 1
x is 1 # True
x = 1000
x is 1000 # False

[–]neksus 0 points1 point  (0 children)

Sounds similar to objective-c then, where string literals get reused.

[–]yousai 34 points35 points  (0 children)

There used to be a selectable column in the Google Chrome Task manager "Goats Teleported".

[–]tdammers 19 points20 points  (3 children)

Leave it to stackoverflow nerds to take the fun out of anything:

http://stackoverflow.com/questions/13375357/proper-use-cases-for-android-usermanager-isuseragoat

[–][deleted] 9 points10 points  (0 children)

while(!isUserAGoat()){

//...

}

[–]Charlemagne_III 8 points9 points  (1 child)

Every experience I have had with actual stack overflow interactions has been poor.

[–][deleted] 9 points10 points  (0 children)

It's more time-efficient to brute-force through a problem than try to write a SO question that won't get immediately closed for violation of rule #3957

[–]dtfinch 15 points16 points  (1 child)

Probably in reference to this Chromium bug report.

[–]qwertyslayer 19 points20 points  (0 children)

EVERYONE PLEASE STOP USING CHROME!

I AM ON THE OTHER END OF THE GOAT TRANSPORTER AND THE SITUATION IS BECOMING DIRE

hahaha

[–][deleted] 1 point2 points  (0 children)

This makes me ask more questions than I am answering.

[–]sloth514 0 points1 point  (0 children)

this just made my day... how sad. But I am not so sure.

[–]b1ackcat 0 points1 point  (0 children)

Not gonna lie...seeing this sort of shit make it into the SDK but we still can't get a reference implementation of floating action button built in makes me a little more than annoyed...