alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (those-kinds-are-high.scala)

This example Scala source code file (those-kinds-are-high.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

a, c1, c1, c2, c2, container, container, list, template, template

The Scala those-kinds-are-high.scala source code

class A {
  trait Container[+T]
  trait Template[+CC[X] <: Container[X]]

  class C1[T] extends Template[C1] with Container[T]
  class C2[T] extends Template[C2] with Container[T]
  
  /** Target expression:
   *    List(new C1[String], new C2[String])
   */
    
  // Here's what would ideally be inferred.
  //
  // scala> :type List[Template[Container] with Container[String]](new C1[String], new C2[String])
  // List[Template[Container] with Container[java.lang.String]]
  //
  // Here's what it does infer.
  // 
  // scala> :type List(new C1[String], new C2[String])
  // <console>:8: error: type mismatch;
  //  found   : C1[String]
  //  required: Container[String] with Template[Container[Any] with Template[Container[Any] with Template[Any] with ScalaObject] with ScalaObject] with ScalaObject
  //        List(new C1[String], new C2[String])
  //             ^
  //
  // Simplified, the inferred type is:
  //
  //   List[Container[String] with Template[Container[Any] with Template[Container[Any] with Template[Any]]]
  //
  
  /** Working version explicitly typed.
   */
  def fExplicit = List[Template[Container] with Container[String]](new C1[String], new C2[String])
  
  // nope
  // def fFail = List(new C1[String], new C2[String])
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala those-kinds-are-high.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.