Scalaforum Scalaforum 2010-01-17T12:07:00+01:00 Tomas Johansson http://www.scalaforum.se Xml och XPath i Scala http://www.scalaforum.se/scala-for-java-utvecklare/scala-xml-java-xpath-implicit-conversions/ 2010-02-12T16:41:00+01:00 Tomas Johansson Kodexemplet visar bl.a. hur man kan "utöka" (med implicit conversion) klassen 'scala.xml.Elem' med en metod som tar emot en XPath-fråga som parameter, och returnerar en 'org.w3c.dom.NodeList'. Using Scala functions to reduce duplication, as alternative to Strategy and Template method design patterns http://www.scalaforum.se/scala-for-java-developers/using-scala-functions-to-reduce-duplication/ 2010-02-12T14:21:00+01:00 2010-01-19T20:04:00+01:00 Tomas Johansson This page has been updated. Essentially, most of the changes are the added final words at the bottom of the page, but there are also some additions in the beginning of the page (i.e. before any larger pieces of code is displayed). Ny FAQ-fråga om utvecklingsmiljöer för Scala http://www.scalaforum.se/faq/#ide 2010-01-17T15:30:00+01:00 2010-02-02T15:59:00+01:00 Tomas Johansson Sidan 'Scala för Java-utvecklare' har omstrukturerats http://www.scalaforum.se/scala-for-java-utvecklare/ 2010-01-25T15:52:00+01:00 2010-01-25T15:52:00+01:00 Tomas Johansson Sidan 'Scala för Java-utvecklare' har nu blivit uppsplittad med länkar till andra sidor i stället för att vara en enda lång sida... Ny sida om Scala utbildningar och events (med eget feed, dvs uppdateringar angående utbildningar/events dupliceras inte till denna feed också) http://www.scalaforum.se/scala-utbildningar-events/ 2010-01-29T16:16:00+01:00 2010-01-25T14:08:00+01:00 Tomas Johansson Scala query expressions can be used for queries similar to some C# LINQ expressions http://www.scalaforum.se/scala-for-java-developers/for-expressions-resembling-dotnet-linq-expressions/ 2010-01-24T23:31:00+01:00 Tomas Johansson Your Scala code can extend existing classes with implicit conversions http://www.scalaforum.se/scala-for-java-developers/extending-existing-classes-with-implicit-conversions/ 2010-01-24T21:24:00+01:00 Tomas Johansson Scala can mix in reusable code into different classes while Java can only inherit from one class http://www.scalaforum.se/scala-for-java-developers/reusing-code-from-different-class-hierarchies/ 2010-01-24T13:42:00+01:00 Tomas Johansson Scala code is less redundant than Java code http://www.scalaforum.se/scala-for-java-developers/scala-less-redundant-verbose-than-java/ 2010-01-23T14:53:00+01:00 Tomas Johansson Scala does not implement the concept of checked exceptions http://www.scalaforum.se/scala-for-java-developers/scala-unchecked-exceptions/ 2010-01-21T17:04:00+01:00 Tomas Johansson Scala - Java - interoperability example using the Spring framework's JdbcTemplate http://www.scalaforum.se/scala-for-java-developers/scala-java-spring-interoperability-example/ 2010-01-20T02:00:00+01:00 Tomas Johansson Using Scala functions to reduce duplication, as alternative to Strategy and Template method design patterns http://www.scalaforum.se/scala-for-java-developers/using-scala-functions-to-reduce-duplication/ 2010-01-19T20:04:00+01:00 2010-01-19T20:04:00+01:00 Tomas Johansson Ny sida 'Scala för Java-utvecklare' http://www.scalaforum.se/scala-for-java-utvecklare/ 2010-01-19T20:08:00+01:00 2010-01-17T15:38:00+01:00 Tomas Johansson Nu finns det en ny sida 'Scala för Java-utvecklare', som syftar till att innehålla enkla kodexempel som kan visa vanliga Java-utvecklare (utan Scala-kunskaper) hur man ofta kan lösa problem (t.ex. refaktoriserad återanvändning av kod med mindre duplicering, utan omständligt kodande som ofta kan krävas då man använder Java) på ett bättre sätt än med Java. FAQ-sida skapad http://www.scalaforum.se/faq/ 2010-01-17T15:30:00+01:00 2010-01-17T15:30:00+01:00 Tomas Johansson Nu finns det en 'FAQ om Scala'. Scala can implement a Java interface for an object without creating a class that implements the interface http://www.scalaforum.se/scala-for-java-developers/implementing-interface-for-object/ 2010-01-17T12:07:00+01:00 2010-01-16T18:15:00+01:00 Tomas Johansson http://www.scalaforum.se/ @scalaforum.se

The purpose of this article is to mainly illustrate these two things: (1) That Scala can be gradually introduced into your project/organization because of the nice interopability with Java (in this code below, there is very little Scala code, but only some Scala implementations of a Java interface) (2) That you can implement an interface for a specific instance, without having to create a class that implements the interface

The initial scenario is that we have some duplicated code which you want to refactor away, but with Java you will need to write a bit more code that you would like to, while the Scala solution is a bit shorter. In the class below, there are two methods that contain exactly the same implementation, but they have different parameters. One of the method receives an instance of the class RandomAccessFile, while the other receives an instance of BufferedReader. It is very important to note that these two classes do NOT ( ! ) share a common base type (except Object) that contains the only used method 'readLine', because if there were such a bae type, then we would be done by simply removing one of the methods, and change the formal parameter type to that common base type with the mehod 'readLine'.