scala> val s: Seq[Class[_ <: java.lang.Enum[_]]] = Seq(classOf[java.util.concurrent.TimeUnit])
s: Seq[Class[_ <: java.lang.Enum[_]]] = List(class java.util.concurrent.TimeUnit)
scala> s.flatMap(_.getEnumConstants)
<console>:9: error: no type parameters for method flatMap: (f: Class[_ <: java.lang.Enum[_]] => scala.collection.GenTraversableOnce[B])(implicit bf: scala.collection.generic.CanBuildFrom[Seq[Class[_ <: java.lang.Enum[_]]],B,That])That exist so that it can be applied to arguments (Class[_ <: java.lang.Enum[_]] => scala.collection.mutable.ArrayOps[_$1(in value $anonfun) with java.lang.Object] forSome { type _$1(in value $anonfun) <: java.lang.Enum[_] })
--- because ---
argument expression's type is not compatible with formal parameter type;
found : Class[_ <: java.lang.Enum[_]] => scala.collection.mutable.ArrayOps[_$1(in value $anonfun) with java.lang.Object] forSome { type _$1(in value $anonfun) <: java.lang.Enum[_] }
required: Class[_ <: java.lang.Enum[_]] => scala.collection.GenTr... s.flatMap(_.getEnumConstants)
उत्तर
नहीं वास्तव में सटीक जवाब के साथ प्राप्त कर सकते हैं, लेकिन दो टिप्पणियों - स्काला 2.10 आप दे देंगे एक अच्छे त्रुटि:
scala> s.flatMap(_.getEnumConstants)
<console>:9: error: no type parameters for method flatMap: (f: Class[_ <: Enum[_]] => scala.collection.GenTraversableOnce[B])(implicit bf: scala.collection.generic.CanBuildFrom[Seq[Class[_ <: Enum[_]]],B,That])That exist so that it can be applied to arguments (Class[_ <: Enum[_]] => scala.collection.mutable.ArrayOps[(some other)_$1(in object $iw) with Object] forSome { type (some other)_$1(in object $iw) <: Enum[_] })
--- because ---
argument expression's type is not compatible with formal parameter type;
found : Class[_ <: Enum[_]] => scala.collection.mutable.ArrayOps[(some other)_$1(in object $iw) with Object] forSome { type (some other)_$1(in object $iw) <: Enum[_] }
required: Class[_ <: Enum[_]] => scala.collection.GenTraversableOnce[?B]
s.flatMap(_.getEnumConstants)
^
<console>:9: error: type mismatch;
found : Class[_ <: Enum[_]] => scala.collection.mutable.ArrayOps[(some other)_$1(in object $iw) with Object] forSome { type (some other)_$1(in object $iw) <: Enum[_] }
required: Class[_ <: Enum[_]] => scala.collection.GenTraversableOnce[B]
s.flatMap(_.getEnumConstants)
^
<console>:9: error: Cannot construct a collection of type That with elements of type B based on a collection of type Seq[Class[_ <: Enum[_]]].
s.flatMap(_.getEnumConstants)
^
और, यदि आप अपनाविभाजित करते हैं
scala> s.map(_.getEnumConstants)
res28: Seq[Array[_$1 with Object] forSome { type _$1 <: Enum[_] }] = List(Array(NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS), Array(RELEASE_0, RELEASE_1, RELEASE_2, RELEASE_3, RELEASE_4, RELEASE_5, RELEASE_6))
scala> res28.flatten
<console>:10: error: No implicit view available from Array[_$1 with Object] forSome { type _$1 <: Enum[_] } => scala.collection.GenTraversableOnce[B].
res28.flatten
^
यही नहीं बल्कि आश्चर्य की बात है जब से तुम लगता है कि है कि यह एक GenTraversableOnce
में एक Array
चालू करने के लिए आसान होना चाहिए: 10, आप समस्या का एक सरल संस्करण देखने को मिलता है। मैं पल में जानकारी खुदाई करने के लिए समय नहीं है, लेकिन मैं निम्नलिखित बातें काम करने के लिए लग रहे हैं कि बाहर बिंदु होगा:, this gist की वजह से है, जो कुछ बहुत ही अजीब से पता चलता
s.flatMap(_.getEnumConstants.toSeq)
s.flatMap(_.getEnumConstants.map(_.asInstanceOf[Enum[_]]))
मैं संकलक बग वोट इस सरल लिपि के लिए आरईपीएल में व्यवहार
val s: Seq[Class[_ <: java.lang.Enum[_]]] = Seq(classOf[java.util.concurrent.TimeUnit], classOf[javax.lang.model.SourceVersion])
s.flatMap(_.getEnumConstants.toSeq)
s.flatMap(_.getEnumConstants.toArray)
1234
TimeUnit.getEnumConstants
एक जावा सरणी TimeUnit[]
देता है, जबकि flatMap
उम्मीद एक GenTraversable
आप द्वारा
scala> s.flatMap(_.getEnumConstants.toSeq)
res4: Seq[Enum[_]] = List(NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS)
फिर s.flatMap (x => ऐरे (1,2,3)) क्यों काम करता है? – themel
क्षमा करें, यह स्पष्ट नहीं था कि मैं जावा एरे के बारे में बात कर रहा था –
मैं उलझन में हूं, मेरी सरल समझ यह है कि जावा टाइमयूनीट [] स्केल में ऐरे [टाइमयूनीट] जैसा ही है, इसलिए कोई अंतर नहीं होना चाहिए, लेकिन हो सकता है मैं गलत हूं। – themel
- 1. यह संग्रहAssert.AreEquivalent() परीक्षण क्यों विफल रहता है?
- 2. यह छोटा से int में क्यों विफल रहता है?
- 3. auto_ptr का यह dynamic_cast क्यों विफल रहता है?
- 4. यह डेटटाइम पार्स हमेशा क्यों विफल रहता है?
- 5. यह Ember.js ऐप फ़ायरफ़ॉक्स में क्यों विफल रहता है?
- 6. यह सरल धागा कोड क्यों विफल रहता है?
- 7. writeToFile विफल रहता है - मैं कैसे डिबग करता हूं यह विफल रहता है (कौन से टूल्स)?
- 8. आईओएस पर एमएमएपी क्यों विफल रहता है?
- 9. ast.literal_eval ('5 * 7') क्यों विफल रहता है?
- 10. स्ट्रीम :: flatMap का यह उपयोग गलत क्यों है?
- 11. WebBrowserTask विफल रहता है
- 12. document.createEvent विफल रहता है
- 13. एक खाली डेटाफ्रेम क्यों है .null() परीक्षण विफल रहता है?
- 14. System.Net.Mail क्यों विफल रहता है System.Web.मेल काम करता है
- 15. गतिशील_कास्ट कैसे विफल रहता है?
- 16. डाउनलोड dSYM विफल रहता है
- 17. gclient runhooks विफल रहता है
- 18. , परिसंपत्ति precompile विफल रहता है
- 19. जब रीडी विफल रहता है
- 20. DQL क्वेरी विफल रहता है
- 21. पुशिंग विफल रहता है - गिटक्रैकन
- 22. यूआई परीक्षण विफल रहता है जब यह एक एक्सकोड बॉट
- 23. यदि गेटड्रिन्फो विफल रहता है तो यह हमेशा के लिए विफल रहता है (नेटवर्क तैयार होने के बाद भी)
- 24. क्यों पाइथन-सीजीआई यूनिकोड पर विफल रहता है?
- 25. क्यों डांसर ऐप uWSGI + अपाचे के तहत विफल रहता है?
- 26. डेटाबेस में परिवर्तनों को सहेजना क्यों विफल रहता है?
- 27. रुबी 2.0 परिष्करण के साथ 'प्रेषण' क्यों विफल रहता है?
- 28. matlab subsref: {} स्ट्रिंग तर्क के साथ विफल रहता है, क्यों?
- 29. COMLInitializeSecurity मेरे डीएलएल में क्यों विफल रहता है?
- 30. यह XDocument प्रमाणीकरण विफल क्यों करता है?
जैसा कि मेरी दूसरी टिप्पणी में बताया गया है, मैं उम्मीद करता हूं कि 'Predef.genericArrayOps'' ऐरे [टाइमयूनीट] 'से' ArrayOps [TimeUnit] 'तक आवश्यक रूपांतरण प्रदान करता है, जो' GenTraversableOnce [TimeUnit] 'से प्राप्त होता है जैसा कि अपेक्षित है 'फ्लैटमैप' कॉल। –
मैं मानता हूं, सवाल यह बताता है कि यह अंतर्निहित ट्रिगर क्यों नहीं करता है (और शायद यह चाहिए)। – themel
मेरा अनुमान है कि यह मुद्दा आवश्यक अंतर्निहित 'CanBuildFrom [Seq [वर्ग [_ <: java.lang.Enum [_]]], टाइमयूनीट, सेक [टाइमयूनीट]]' से संबंधित है, लेकिन फिलहाल मैं कर सकता हूं यह नहीं पता कि कौन सी स्रोत फ़ाइल में डिफ़ॉल्ट निहित टाइपक्लास बिल्डर्स हैं। मुझे लगता है कि स्कैला-उपयोगकर्ता समूह को पोस्ट करने से कुछ और सूचित उत्तर मांगे जाएंगे। –