The Artima Developer Community
Sponsored Link

Programming in Scala Forum
Scala IO (and printf)

4 replies on 1 page. Most recent reply: Jan 25, 2008 8:22 PM by Matthew Passell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Toby Donaldson

Posts: 8
Nickname: tjd
Registered: Jun, 2003

Scala IO (and printf) Posted: Dec 24, 2007 9:22 PM
Reply to this message Reply
Advertisement
Except for a few examples, I don't see a section on the "Scala way" of doing IO. For example, if I want to process files and folders, should I just use Java classes? Or does Scala provide a more convenient way?

And speaking of convenience, is there any way to use C-style printf statements in Scala, as can be done in more recent versions of Java, e.g.
System.printf("%4d: %s\n", lineNum, line);

I've looked at Console.printf, but it's not a C-style print; I haven't yet figure out how to simulate this using Java's MessageFormat syntax.


Lex Spoon

Posts: 6
Nickname: lexspoon
Registered: Oct, 2006

Re: Scala IO (and printf) Posted: Dec 27, 2007 10:13 AM
Reply to this message Reply
You should use the Java classes. Scala does add print and println for convenience, but generally leaves IO up to Java.

Toby Donaldson

Posts: 8
Nickname: tjd
Registered: Jun, 2003

Re: Scala IO (and printf) Posted: Dec 28, 2007 3:13 PM
Reply to this message Reply
Thanks ... if only I could figure out how to call Java vararg functions in Scala. :-)

Matthew Passell

Posts: 6
Nickname: mpassell
Registered: Jul, 2004

Re: Scala IO (and printf) Posted: Jan 25, 2008 8:18 PM
Reply to this message Reply
You may know this already, but varargs in Java are just syntactic sugar for arrays. So the method signature
<code>public Object doSomething(Integer... ints)</code>
compiles to be the equivalent of
<code>public Object doSomething(Integer[] ints)</code>
Given that, I would imagine you could call varargs methods in Java classes just as you would ones taking arrays.

Matthew Passell

Posts: 6
Nickname: mpassell
Registered: Jul, 2004

Re: Scala IO (and printf) Posted: Jan 25, 2008 8:22 PM
Reply to this message Reply
You may know this already, but varargs in Java are just syntactic sugar for arrays. So the method signature public Object doSomething(Integer... ints) compiles to be the equivalent of public Object doSomething(Integer[] ints). Given that, I would imagine you could call varargs methods from Scala just as you would ones that take arrays as parameters.

Flat View: This topic has 4 replies on 1 page
Topic: Error in Chapter 6: p119 Previous Topic   Next Topic Topic: Do you really need a chapter on stateful objects?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use