Pattern-matching in a context unrelated to error-handling:
(in.read, in.read, in.read, in.read) match {
case (0xCA, 0xFE, 0xBA, 0xBE) => println("It's a Java class file!")
case (0xFE, 0xCA, 0xBE, 0xBA) => println("It's in rioplatense!")
case _ => println("Not a clue.")
}
Corresponds to the Java:
List<Integer> input = new ArrayList<Integer>();
for (int a = 0; a < 4; a++)
input.add(in.read());
if (input.equals(Arrays.asList(0xCA, 0xFE, 0xBA, 0xBE)))
System.out.println("It's a Java class file!");
else if (input.equals(Arrays.asList(0xFE, 0xCA, 0xBE, 0xBA))
System.out.println("It's in rioplatense!");
else
System.out.println("Not a clue.");
On Thu, Sep 23, 2010 at 12:26 AM, Miroslav Pokorny <
[email protected]> wrote:
> It seems to me that Kevin always unconditionally says some construct unique
> to Scala is better than a Java equivalent even giving examples and
> reasonings that are for all intents and purposes identical in form,
> functionality and readability... The try catch example for opening a file is
> perfect example.
>
> Kevin please give examples with real differences!!!
>
> --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<javaposse%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.