Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3977002
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:52:19+00:00 2026-05-20T04:52:19+00:00

Scala Where can differences between a class and a type be observed in Scala

  • 0

Scala

Where can differences between a class and a type be observed in Scala and why is this distinction important?

Is it only a consideration from the language design point-of-view or has it “practical” impact when programming Scala?

Or is it fundamental to “securing the boundaries” of the type system (Nothing, Null come to my mind)?

Java

How many of the considerations/differences/problems mentioned above can also be recognized in Java?


(See What is the difference between Type and Class? as a language-agnostic introduction.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:52:19+00:00Added an answer on May 20, 2026 at 4:52 am

    When you say “type” I’m going to assume you mean static type mostly. But I’ll talk about dynamic types shortly.

    A static type is a property of a portion of a program that can be statically proven (static means “without running it”). In a statically typed language, every expression has a type whether you write it or not. For instance, in the Cish “int x = a * b + c – d”, a,b,c,and d have types, a * b has a type, a * b + c has a type and a * b + c -d has a type. But we’ve only annotated x with a type. In other languages, such as Scala, C#, Haskell, SML, and F#, even that wouldn’t be necessary.

    Exactly what properties are provable depends on the type checker.

    A Scala style class, on the other hand, is just the specification for a set of objects. That specification includes some type information and includes a lot of implementation and representation details such as method bodies and private fields, etc. In Scala a class also specifies some module boundaries.

    Many languages have types but don’t have classes and many languages have classes but don’t have (static) types.

    There are several observable differences between types and classes. List[String] is a type but not a class. In Scala List is class but normally not a type (it’s actually a higher kinded type). In C# List isn’t a type of any sort and in Java it’s a “raw type”.

    Scala offers structural types. {def foo : Bar} means any object that provably has a foo method that returns a Bar, regardless of class. It’s a type, but not a class.

    Types can be abstracted using type parameters. When you write def foo[T](x : T) = …, then inside the body of foo T is a type. But T is not a class.

    Types can be virtual in Scala (i.e. “abstract type members”), but classes can’t be virtual with Scala today (although there’s a boilerplate heavy way to encode virtual classes https://wiki.scala-lang.org/display/SIW/VirtualClassesDesign)

    Now, dynamic types. Dynamic types are properties of objects that the runtime automatically checks before performing certain operations. In dynamically typed class-based OO languages there’s a strong correlation between types and classes. The same thing happens on JVM languages such as Scala and Java which have operations that can only be checked dynamically such as reflection and casting. In those languages, “type erasure” more or less means that the dynamic type of most objects is the same as their class. More or less. That’s not true of, e.g., arrays which aren’t typically erased so that the runtime can tell the difference between Array[Int] and Array[String]. But remember my broad definition “dynamic types are properties of objects that the runtime automatically checks.” When you use reflection it is possible to send any message to any object. If the object supports that message then everything works out. Thus it makes sense to talk of all objects that can quack like a duck as a dynamic type, even though it’s not a class. That’s the essence of what the Python and Ruby communities call “duck typing.” Also, by my broad definition even “zeroness” is a dynamic type in the sense that, in most languages, the runtime automatically checks numbers to make sure you don’t divide by zero. There are a very, very few languages that can prove that statically by making zero (or not-zero) a static type.

    Finally, as other’s have mentioned, there are types like int which don’t have a class as an implementation detail, types like Null and Any which are a bit special but COULD have classes and don’t, and types like Nothing which doesn’t even have any values let alone a class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please explain the major differences between Scala, Groovy and Clojure. I know
This a very simple scala sample, but it can't be compiled: abstract class Box[+A]
What are the key differences between the approaches taken by Scala and F# to
Can someone please identify the functional/performance differences, if any, between SET and SELECT in
Anyone can tell me the difference between func _ and func(_) in Scala? I
I was checking out a tutorial, found at http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-4 This tutorial is from jan.
What are the differences among Streams, Views (SeqView), and Iterators in scala? This is
One can write scripts in Scala. So you can put this into Hello.scala #!/bin/sh
how can I import the following package: org.hibernate.type.StringType in Scala? If I do: import
Scalar-valued functions can be called from .NET as follows: SqlCommand cmd = new SqlCommand(testFunction,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.