In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will give you a detailed explanation on how to achieve Drag language design, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Virtual machines, cross-platform
Drag virtual machine, similar to python virtual machine, java virtual machine.
It is both a static language and a dynamic language.
When a class implements the dynamic interface, the class supports the operation of dynamically adding properties and methods. Otherwise, the class checks whether the operation is legal at compile time.
Everything is an object, and all objects are derived from classes.
Similar to removing the primitive type of java.
Virtual machine built-in type ObjectDynamicBooleanByteIntegerLongFloatDoubleStringMapList
Distinguish between Float and Double by using numbers followed by _ d or _ f to distinguish between Integer and Long using numbers followed by _ I or _ l
You can define or not define a reference type
Integer await 10; you can also await 10; when no reference type is defined, the default is the Object type.
You can use either {} or indentation or a combination of both, but force code indentation. Public class A {void printString () {print ("str");}} public class A void printString () print ("str"); if and for, swith and while
No swith, no while.
If// ordinary version if () {} else if () {} else {} / / abbreviated version if () {} ef () {} el {} forfor (Boolean) / / similar whilefor (Var;Boolean;Increment) / / normal forfor (Var in Iterator) / / similar python supports goto
Goto can only be used within a method and can only be goto back to a tag. Break tags similar to java, but not limited to use within loops.
[String] ss= ["str1", "str2"]; for (s in ss) if (slots = "str2") goto Aprint ("run..."); / / this line of code will be skipped: a jump / jump here to support multi-line string code writing method String s = "sssssss"; comment
Same as java, but single-line support #
Naming rules
Same as java, but cannot use $
A non-private attribute subclass defined by a parent class cannot define an attribute with a duplicate name. Binary system
Default decimal binary: the number begins with 28, the number begins with 816, the number begins with 16 _, and so on.
Support to return multiple return values public static String,Integer getInfo () return "zs", 10 to public static main (List s) String name,Integer age=getInfo (); array
List similar to java
The definition of the array (generic writing) List array=new List (); / if you are in the constructor new List (Integer); if you pass in parameters, you can fix the array length List array=new List (); List array= ["str1", "str2"]; [String] array=new List (); [String] array=new List (); [String] array= ["str1", "str2"]; the definition of the array (non-generic writing, the effect is equal to [Object]) List array=new List (); List array=new List () List array= ["str1", "str2"]; [] array=new List (); [] array=new List (); [] array= ["str1", "str2"]
Use:
[String] array= ["str1", "str2"]; String v=array [0]; String v=map.get (0); dictionary definition (generic writing) Map map=new Map (); / / if you are in the constructor new Map (Integer); input parameters can be fixed dictionary length Map map=new Map (); Map map= {"key1": 10, "key2": 20} {String:Integer} map=new Map (); {String:Integer} map=new Map () {String:Integer} map= {"key1": 10, "key2": 20} dictionary definition (non-generic, effect equals {Object:Object}) Map map=new Map (); Map map=new Map (); Map map= {"key1": 10, "key2": 20} {} map=new Map (); {} map=new Map (); {} map= {"key1": 10, "key2": 20}
Support multiple value corresponding to one key
{String:Integer:Integer} map= {"key1": 10:11, "key2": 20:21}
Use:
{String:Integer} map= {"key1": 10, "key2": 20} Integer v=map ["key1"]; Integer v=map.get ("key1"); {String:Integer:Integer} map= {"key1": 10:11, "key2": 20:21} Integer v1Magne Integer v2=map ["key1"]; Integer v1Magne Integer v2=map.get ("key1"); ordinary class
By default a common class is a static class (as opposed to a dynamic class). Define static type classes:
Class A {}
Use statically typed objects:
An a=new A (); a.name = "tzc" / / compilation error A has no an attribute a=new A (); a.name = "tzc" / / compilation error Object has no an attribute interface
Define using the interface keyword.
Interface A {}
Or:
Interface class A {}
Interfaces are special classes. Methods are public to the instance, have no properties, and must be inherited in order to new.
Constant class
Define using the constant keyword.
Constant A {}
Or:
Constant class A {}
Constant classes are special classes. Properties and methods are static and cannot be inherited.
Final state class
Define using the final keyword.
Final A {}
Or:
Final class A {}
The final state class is a special class. Can't be inherited.
The final keyword is basically the same as java, but can be used in the following ways:
{String:Integer} values in map=final {"key1": 10, "key2": 20} / / map cannot be modified, values in element [String] array=final ["str1", "str2"] / / array cannot be modified, element Student stu=new final Student ("zhangsan", 20) cannot be added and deleted; attributes in / / stu cannot be modified, attribute dynamic classes cannot be added and deleted.
Define using the dynamic keyword.
Dynamic A {/ / this definition means that the class implements the Dynamic interface}
Or:
Dynamic class A {/ / this definition indicates that the class implements the Dynamic interface}
Or implement the Dynamic interface:
Class An implement Dynamic {}
Dynamic classes are special classes. Compile type checking can be avoided.
Use dynamically typed objects:
An a=new A (); a.name = "tzc" / / compiles and runs the correct Dynamic a=new A (); a.name = "tzc" / / compiles and runs the correct a=new A (); a.name = "tzc" / / compilation error dynamic:class A {} a=new dynamic A () when the Object has no an attribute a=new dynamic; / / if A does not implement Dynamic, then an is an object that implements An and implements the Dynamic subclass, which is tantamount to creating an anonymous class. A. name = "tzc" / / compile and run the correct a=dynamic 10. A=dynamic String;//an is an object that inherits Integer and implements the subclass of Dynamic. A=dynamic String;//an is an object that inherits String and implements the subclass of Dynamic. The object can be used in the front-end browser instead of javascript, requiring browser support, and developers only need to import the corresponding library. API, the core API has only built-in types, and you have to add different libraries if you want to develop.
The basic version of API is similar to JavaSE, and the premium version of API is similar to JavaEE.
On how to achieve Drag language design to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.