Quantcast
Channel: a computer hobbyist's notebook - Java
Viewing all articles
Browse latest Browse all 13

The difference between pets and meat, in Java

$
0
0
enum Pet {
    DOG, CAT, PIG, RAT, FISH, COW, CHICKEN
}

enum Meat {
    DOG, CAT, PIG, RAT, FISH, COW, CHICKEN
}

class animals {
    public static void main(String[] args) {
        Pet pet = Pet.PIG;
        Meat meat = Meat.PIG;

        if (pet==meat) {
            System.out.println("same");
        } else {
            System.out.println("different");
        }
    }
}

When you try to compile this:

animals.java:14: incomparable types: Pet and Meat
        if (pet==meat) {
               ^
1 error

Java distinguishes between pigs as pets and pigs as meat. So much so that it won't even compile. I suspect Java is one of those ardent meat-eating-vegetarian-hating, inflexible thinkers.


Viewing all articles
Browse latest Browse all 13

Trending Articles