java - Puzzling implicit conversion during Array map() -


I have a usage case where I get the Java array of wrapper sections, for example wrapping a gut, and I want to I wanted to convert them to the same data value, but I had a problem with missing conversions here. Here's an example of Java and Scala that I'm trying to do:

.. / java / demoapi / somewrapper.java

  package demo; Public Class SomeWrapper {public static final full JavaOne = 1; Public stable final end JavaTwo = 2; Public int m_theInt; };  

... / scala / demo.scala

package demotest import demoapi._Office extension of TestEnum calculation {val one, two = value} object SomeWrapperEx {in Java (from: array [SomeWrapper]): TestEnum.ValueSet = {in.map (x = & gt; fromInt (x.m_theInt)}} def fromInt (in: Int): TestEnum.Value = {match {Case SomeWrapper.JavaOne => TestNen.A case: SomeWrapper.JavaTwo => TestEnum.Two}}}

The map fails to compile with the following error: < / p>

  error (11, 27) values ​​m_theInt is not a member Demotest.TestEnum.Value in.map (x = & gt; fromInt (x.m_theInt)) ^  

My question is: How was the type of ray changed to a TestEnum.Value already? I had to work around except for such barriers, but I think it should work some way ...

Edit: I'm sure that I have to do more to work, like maybe converting the array [TestEnum.Value] to a value, but I have not yet found it at that point.

You are hoping to convert your arrays into archaeops so that you work on it Able to do

But you are hoping to prepare the valuation, and to do so, the machinery is one way to make it, a cannabilfrom.

It is here as under:

.

Since you will provide a way to convert your array into a valuset, use it to be available to CanBuildFrom, please apply it joyfully.

-Xprint: typer lets you view towards taking it:

  implicit def Java (Score: Arre [Demoapi. Some Wedding ]): Demo Test Annam. Value = some warper x this. Jeva (in) .map [nothing, demo api. Test en Valuset] (((x: Demoapi. Tiitianm. Value) = & gt; SomeWrapperEx.this.fromInt (x. And lt; m_theInt: error & gt;))) (demoapi.This.TestEnum.ValueSet.canBuildFrom);  

I also participate in problems with working with ValueSet as a general collection, so now I do not. For example,

, always start with a Valuset:

  $ scala Scala version Welcome to 2.11.2 (Java HotSpot (TM) 64-Bit Server VM , Java 1.8.0_05). Type them in the expression to evaluate them. Type: Support for more information> Scala & gt; Extend the volume of the object day {Val M, T, W, C, F, S, S = Value} Defined object marks of the day & gt; Val DS = (2 to 5) .toArray DS: array [int] = array (2, 3, 4, 5) scale & gt;  

Or hand-built:

> Scala & gt; Days.ValueSet.empty res1: Days.ValueSet = Days.ValueSet () Scale & gt; Res1 + Day Res2: Day. Value = day Valueset (t)

Any canbillid anyway:

  scala> Vested xxx = new collection. Generic.CanBuildFrom [array [int], day. Value, day ValueSet] {| Def apply () = day. Value Asset | Def apply (from: array [int]) = apply () | } Xxx: scala.collection.generic.CanBuildFrom [array [int], day Value, day Value] = $ anon $ 1 @ 6b474074 scale & gt; (2 of 5) Map (= _ & gt; day.) Res4: scala.collection.immutable.IndexedSeq [Days.Value] = vector (T, T, T, T) Skale & gt; (2 5) Show (day (_)) res5: scala.collection.immutable.IndexedSeq [Days.Value] = vector (W, Th, F, Sa)  
< / Html>

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -