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

Scala example source code file (t3453.scala)

This example Scala source code file (t3453.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, a, b, b, o, s, s, t1, t2a, t2b, t2b, t3

The Scala t3453.scala source code

// test shadowing of implicits by synonymous non-implicit symbols
// whether they be inherited, imported (explicitly or using a wildcard) or defined directly
class A
class B

trait S {
    implicit def aToB(a: A): B = new B
}

class T1 extends S {
    def x: B = {
        val aToB = 3
        // ok: doesn't compile, because aToB method requires 'T.this.' prefix
        //aToB(new A)

        // bug: compiles, using T.this.aToB,
        //   despite it not being accessible without a prefix
        new A
    }
}

object O {
    implicit def aToB(a: A): B = new B
}

class T2a {
    import O._
    
    def x: B = {
        val aToB = 3
        // ok: doesn't compile, because aToB method requires 'T.this.' prefix
        //aToB(new A)

        // bug: compiles, using T.this.aToB,
        //   despite it not being accessible without a prefix
        new A
    }
}

class T2b {
    import O.aToB
    
    def x: B = {
        val aToB = 3
        // ok: doesn't compile, because aToB method requires 'T.this.' prefix
        //aToB(new A)

        // bug: compiles, using T.this.aToB,
        //   despite it not being accessible without a prefix
        new A
    }
}

class T3 {
    implicit def aToB(a: A): B = new B
    
    def x: B = {
        val aToB = 3
        // ok: doesn't compile, because aToB method requires 'T.this.' prefix
        //aToB(new A)

        // bug: compiles, using T.this.aToB,
        //   despite it not being accessible without a prefix
        new A
    }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala t3453.scala source code file:

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

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.