Hi Moon,

thank you for pointing me in the right direction. Knowing that this is an
inherent limitation of scala worksheets it was much easier to debug and to
find a workaround. Here is my take on  it:

```
case class JsonKey(name: String)

object Email extends JsonKey("email")
object FacebookId extends JsonKey("facebook_id")

trait EventProcessor extends Serializable {
  def extractId(id: Int,
                jsonKey: JsonKey): Option[Int] = {
    //Business logic (not relevant for the question)
    println(jsonKey.name)
    None
  }
}

object EventProcessorImpl extends EventProcessor{
}

EventProcessorImpl.extractId(1, Email)
```

The semantics is not exactly the same as before, but it is fine. My goal is
to have as minimal changes in comparison to the real codebase as possible
for quickly testing things out. The workaround serves this purpose.

Regards,
Alexander Fedulov


On Thu, Oct 15, 2015 at 3:19 PM, moon soo Lee <m...@apache.org> wrote:

> I tried the code with both scala-2.10.4 and spark-shell, and the results
> were the same. Looks like scala repl does not allow such usage.
> Someone who have better scala experience in this mailing list or scala
> community can help you. http://www.scala-lang.org/community/
> Let me know if there're anything i can help.
>
> Best,
> moon
>
> On Thu, Oct 15, 2015 at 12:17 PM Alexander Fedulov <
> alexander.fedu...@gmail.com> wrote:
>
>> Hi Moon,
>>
>> here is a simplified example. Both the object and the trait are defined
>> in the same section.
>>
>> ```
>> object JsonKey {
>>   sealed abstract class JsonKey(_name: String) {
>>     def name = _name
>>   }
>>   case object Email extends JsonKey("email")
>>   case object FacebookId extends JsonKey("facebook_id")
>> }
>>
>>
>> trait EventProcessor extends Serializable {
>>
>>   def extractId(id: Int,
>>                 jsonKey: JsonKey,
>>                 map: java.util.Map[String,AnyVal]): Option[Int] = {
>>     //Business logic (not relevant for the question)
>>     None
>>   }
>> }
>>
>> ```
>>
>> Output:
>>
>> ```
>> defined module JsonKey <console>:22: error: not found: type JsonKey
>> jsonKey: JsonKey, ^
>> ```
>>
>>
>> Regards,
>> Alexander Fedulov
>>
>>
>> On Thu, Oct 15, 2015 at 7:54 AM, moon soo Lee <m...@apache.org> wrote:
>>
>>> Hi Alexander fedulov,
>>>
>>> Thanks for the sharing the problem. If you can share an example about
>>>
>>> however, when later I try to use it in a function definition within a
>>> trait, I get an error:
>>>
>>> that would be more helpful.
>>>
>>> Thanks,
>>> moon
>>>
>>> On Wed, Oct 14, 2015 at 1:26 PM <ijustwanttoregis...@googlemail.com>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> I would like to use an Object in a Zeppelin notebook, something like:
>>>>
>>>> object JsonKey {
>>>>   sealed abstract class JsonKey(_name: String) {
>>>>     def name = _name
>>>>   }
>>>>   case object Email extends JsonKey("email")
>>>>   case object FacebookId extends JsonKey("facebook_id")
>>>> }
>>>>
>>>> however, when later I try to use it in a function definition within a
>>>> trait, I get an error:
>>>>
>>>> <console>:45: error: not found: type JsonKey jsonKey: JsonKey,
>>>>
>>>> What is the problem, and is there a workaround for it?
>>>>
>>>> Regards,
>>>> Alexander fedulov
>>>>
>>>
>>

Reply via email to