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 8157541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:19:13+00:00 2026-06-06T17:19:13+00:00

Reading the Scala by Example book and there is this example when Martin explains

  • 0

Reading the Scala by Example book and there is this example when Martin explains type bounds on page 54:

trait Set[A <: Ordered[A]] {
  def incl(x: A): Set[A]
  def contains(x: A): Boolean
}

and

trait Set[A <% Ordered[A]] ...

further on page 55. He also says that the <:/<% is the only change required for trait Set in order to demonstrate the type bounding possibilities.

However, when I repeat the example with my own code, the IDE complains that traits may NOT have view bounds, only type bounds. Changing the trait keyword to abstract class or changing the view bound to type bound helps. Is this a mistake in the book?

  • 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-06-06T17:19:14+00:00Added an answer on June 6, 2026 at 5:19 pm

    Let’s use our powerful tool called the REPL to understand what is going on:

    scala>  trait Example[A<:Ordered[A]] { def contains(x:A):Boolean }
    defined trait Example
    
    scala>  class Example2[A<%Ordered[A]]( val a:A) { def isLower(otherA:A):Boolean = a< otherA }
    defined class Example2
    
    scala>  :javap Example
    Compiled from "<console>"
    public interface Example{
        public abstract boolean contains(scala.math.Ordered);
    }
    
    
    scala>  :javap Example2
    Compiled from "<console>"
    public class Example2 extends java.lang.Object implements scala.ScalaObject{
        public java.lang.Object a();
        public boolean isLower(java.lang.Object);
        public Example2(java.lang.Object, scala.Function1);
    }
    

    As you can see , the view bound becomes the second argument of the Example2 constructor. Since a trait does not have a constructor, clearly it is not possible to provide a view bound.

    Why this has been possible in previous releases is to me a mistery (maybe an additional Function1 val was created inside the trait and filled by the compiler?)

    Concerning your question about Scala evolution, it is mature and powerful. You can expect changes between major releases (2.8, 2.9, 2.10) but I would not consider scala not mature enough for this. There is, however, always space for improvement

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

Sidebar

Related Questions

Im reading this page http://www.scala-lang.org/node/137 , I understand what covariance is and lower bounds
I am reading the Scala in Examples book and almost every example there has
I am reading Martin Odersky's Programming in Scala , and I have been using
I'm reading a book on scala programming (the Programming in Scala), and I've got
I'm reading the Programming in Scala book by the Scala Creator and I'm a
From reading parts of the Programming in Scala book, I realize that Scala can
I've recently wanted to give Scala a try and I started by reading book
Reading this question on importing ColorData from matlab, I was wondering if there is
I just finished reading a book on scala. What strikes me is that every
Are there public instance variables anymore in Scala? I'm reading Programming in Scala ,

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.