简体   繁体   English

使用Scala就像它是Java一样

[英]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. 我最近一直在阅读Scala,我真的很想进入它。 I do my Java web development from within Eclipse with Tomcat as my preferred server and I'd like to keep it that way. 我在Eclipse中使用Tomcat作为我的首选服务器进行Java Web开发,并且我希望保持这种方式。 I've tried the Scala Eclipse plugin but it's safe to say, it isn't there yet. 我已经尝试过Scala Eclipse插件,但可以肯定地说,它还没有。 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). 最重要的是,它似乎没有为Web项目提供任何东西(我可能在那里错了)。

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? 由于Scala是一种编译语言,就像Java一样,我想知道是否可以简单地用Scala替换Java,就像我通常会创建Java类一样,我现在可以创建Scala类了吗? Maybe even mix Java and Scala? 也许甚至混合Java和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? 有没有人能够在Eclipse中为Web开发设置一个像样的Scala工作流程而没有可怕的“官方”Scala Eclipse插件?

PS: I've tried the Play framework (I think it recently added Scala support) but it simply isn't for me. PS:我已经尝试过Play框架(我认为它最近添加了Scala支持),但它根本不适合我。 I like my classes compiled and to use JSP's for my views. 我喜欢编译的类,并使用JSP作为我的视图。

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. 您没有说明您使用的Eclipse的Scala IDE版本,或者您尝试解决问题的方法。 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. 我建议您在更改工作流程之前,先访问http://groups.google.com/group/scala-ide-user ,看看我们是否可以帮到您。

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? 由于Scala是一种编译语言,就像Java一样,我想知道是否可以简单地用Scala替换Java,就像我通常会创建Java类一样,我现在可以创建Scala类了吗?

Yes, absolutely. 是的,一点没错。 That's one of Scala's big advantages over some other JVM languages. 这是Scala比其他一些JVM语言更大的优势之一。

Maybe even mix Java and Scala? 也许甚至混合Java和Scala?

Yes, absolutely. 是的,一点没错。 That's one of Scala's big advantages over some other JVM languages. 这是Scala比其他一些JVM语言更大的优势之一。

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). 确保您熟悉Java和Scala集合库(并且保持它们正确 - 如果您计划在Java集合上使用高级Scala功能,那么肯定使用Scala 2.8候选版本)。 Also make sure you're faimilar with the @BeanProperty annotation -- it can simplify your Scala coding somewhat. 还要确保你与@BeanProperty注释很相似 - 它可以在某种程度上简化你的Scala编码。

As Miles said, you should give us the version of Eclipse you are working with. 正如迈尔斯所说,你应该给我们你正在使用的Eclipse版本。

I'm also new to Scala and found difficult to work through Eclipse. 我也是Scala的新手,发现很难通过Eclipse工作。 I was using Eclipse Galileo 3.5.2 and found specially long to compile all the scala libraries. 我正在使用Eclipse Galileo 3.5.2并且发现特别长时间来编译所有scala库。 I switched to IntelliJ (IDEA 9.0.2) and I'm much more confortable now. 我切换到IntelliJ(IDEA 9.0.2),现在我更加舒适。 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. 即便如此,我同意,插件还没有特别用于Web开发。 The great news is that you can use everything you have in Java and mix it with Scala. 好消息是,您可以使用Java中的所有内容并将其与Scala混合使用。 Since Scala is compiled to Java BitCode, they are totally compatible. 由于Scala编译为Java BitCode,因此它们完全兼容。 See Combining Scala and Java . 请参阅组合Scala和Java

When writing in Scala you always have (almost) all the Java libraries at your service plus anything you have created before. 在Scala中编写时,您总是拥有(几乎)所有Java库以及之前创建的所有Java库。 You will have to be carefull with the types (ie primitive types) but it normally works out very well. 您将不得不小心类型(即原始类型),但它通常很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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