Scala Language Specification से, खंड 8.1 पैटर्न दिखाई देता है तो सक्षम हो सकता है के बाद: क्या, एक प्रकार पैटर्न के रूप में जाना जाता है धारा 8.2 में परिभाषित करने की जरूरत है:
Type patterns consist of types, type variables, and wildcards. A type pattern T is of one of the following forms:
...
A parameterized type pattern T [a(1), . . . , a(n)], where the a(i) are type variable patterns or wildcards _. This type pattern matches all values which match T for some arbitrary instantiation of the type variables and wildcards. The bounds or alias type of these type variable are determined as described in (§8.3).
...
A type variable pattern is a simple identifier which starts with a lower case letter. However, the predefined primitive type aliases unit, boolean, byte, short, char, int, long, float, and double are not classified as type variable patterns.
तो, वाक्य रचनात्मक रूप से, आप इस स्थिति में एक प्रकार परिवर्तनीय पैटर्न के रूप में पूरी तरह से योग्य वर्ग का उपयोग नहीं कर सकते हैं। हालांकि, आप एक प्रकार के उपनाम का उपयोग कर सकते हैं, इसलिए:
type JavaInt = java.lang.Integer
List(new java.lang.Integer(5)) match {
case y: Seq[JavaInt] => 6
case _ => 7
}
अपेक्षित 6 लौटाएगा। समस्या यह है कि एलन बर्लिसन बताते हैं कि निम्नलिखित 6:
List("foobar") match {
case y: Seq[JavaInt] => 6
case _ => 7
}
क्योंकि प्रकार मिटाया जा रहा है। आप आरईपीएल, या स्केलैक को अनचेक विकल्प के साथ चलाकर देख सकते हैं।
वाह। मैंने आज इसे मारा और अंततः यह सवाल पाया। मुझे स्केल में "टाइप वैरिएबल पैटर्न" जैसी कोई चीज़ नहीं थी। एसएलएस में अभी भी मुझसे क्या छुपा रहा है ...? –
कुछ ईस्टर अंडे केवल 1/4 और ईस्टर पर सक्रिय होते हैं। –
मैंने https://groups.google.com/d/msg/scala-language/2PNDjkI47Ao/MCQw7RzNUwcJ –