简体   繁体   中英

Use Scala as if it was Java

I've been reading up on Scala a lot recently and I really want to get into it. I do my Java web development from within Eclipse with Tomcat as my preferred server and I'd like to keep it that way. I've tried the Scala Eclipse plugin but it's safe to say, it isn't there yet. I had to uninstall it because it simply ins't working. On top of that, it doesn't seem to provide anything for doing web projects (I could be wrong there).

Since Scala is a compiled language just like Java is, I was wondering if it's possible to simply swap out Java with Scala, as in, where I'd normally would create Java classes I would now be able to create Scala classes instead? Maybe even mix Java and Scala?

Is there anyone out there who's been able to set up a decent Scala workflow in Eclipse for web development without the dreaded "official" Scala Eclipse Plugin?

PS: I've tried the Play framework (I think it recently added Scala support) but it simply isn't for me. I like my classes compiled and to use JSP's for my views.

You don't say anything about what version of the Scala IDE for Eclipse you were using, or what you tried to do to resolve your issues. I suggest that before changing your workflow you head over to http://groups.google.com/group/scala-ide-user and see if we can help you out.

Since Scala is a compiled language just like Java is, I was wondering if it's possible to simply swap out Java with Scala, as in, where I'd normally would create Java classes I would now be able to create Scala classes instead?

Yes, absolutely. That's one of Scala's big advantages over some other JVM languages.

Maybe even mix Java and Scala?

Yes, absolutely. That's one of Scala's big advantages over some other JVM languages.

Make sure you have familiarity with the Java and Scala collections libraries (and that you keep them straight -- if you're planning using advanced Scala features on Java collections, definitely use a Scala 2.8 release candidate). Also make sure you're faimilar with the @BeanProperty annotation -- it can simplify your Scala coding somewhat.

As Miles said, you should give us the version of Eclipse you are working with.

I'm also new to Scala and found difficult to work through Eclipse. I was using Eclipse Galileo 3.5.2 and found specially long to compile all the scala libraries. I switched to IntelliJ (IDEA 9.0.2) and I'm much more confortable now. I recomend trying it although it's more a personal matter.

Even so, I agree, the plugins are not there yet specially for web development. The great news is that you can use everything you have in Java and mix it with Scala. Since Scala is compiled to Java BitCode, they are totally compatible. See Combining Scala and Java .

When writing in Scala you always have (almost) all the Java libraries at your service plus anything you have created before. You will have to be carefull with the types (ie primitive types) but it normally works out very well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM