Scala HTTP Server pt 3 – Request case class

Ok, this is another example of a Case class and, as this is all that’s in this post I’ll attempt some further explanation of this nice feature of Scala.

First, here is the class:

package com.vff.scalahttp

case class Request(method:String, resource:String)

Now, here is the Java equivalent:

package com.vff.scalahttp;

public class Request {

  private String method;
  private String resource;

  public Request(final String method, final String resource) {
    this.method = method;
    this.resource = resource;
  }

  public String getMethod() {
    return method;
  }

  public String getResource() {
    return resource;
  }
}

A case class is a nice construct I typically use for holding data in an immutable way.
Here is the ‘official’ definition: http://www.scala-lang.org/old/node/107

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s