|
Java 8 |
C # 6 |
Swift |
Variable |
Type variable name; |
Type variable name; |
var variable name: type; |
Variable (type inference) |
N/A |
var variable name = initial value; |
var variable name = initial value; |
Constant |
Final type constant name = initial value; |
ReadOnly type constant name = initial value; |
Let constant name: type = initial value; |
Basic type |
int short Long byte Double float Boolean Char |
int short Long byte Double float bool Char |
Int32 Int16 Int64 Int8 Double Float Bool Character |
String |
String Variable name = ""; |
String variable name = ""; |
Let variable name: string= ""; |
String embedding value |
N/A |
"\{Expression}" |
"\ (expression)" |
Variable string |
StringBuilder |
StringBuilder |
var variable name: String; |
Fixed constant group |
Type [] Variable name ={element 1, Element 2}; |
Type [] Variable name ={element 1, Element 2}; |
Let variable name: type name [] = [element 1, Element 2]; |
Variable-length arrays (list) |
arraylist< type > |
list< type > |
var variable name = type name [] (); |
Append element |
Add |
Add |
Append |
Traverse |
For (type variable: collection) |
foreach (type variable in collection) |
for (variable in collection) |
Dictionary |
treemap< key types, value types > |
dictionary< key types, value types > |
dictionary< key types, value types > |
Dictionary initialization |
treemap< key type, value type > variable name = new treemap< key type, value type > () { { Put (key 1, value 1); Put (key 2, value 2); } }; |
var variable name = new dictionary< key type, value type > () { [Key 1] = value 1, [Key 2] = value 2, }; |
var variable name: dictionary< key Type, value type >= [ Key 1: value 1, Key 2: Value 2 ]; |
Dictionary subscript |
N/A (using the Get method) |
Variable name [key] |
Variable name [key] |
Defining Functions (Methods) |
return type method Name (parameter type 1, parameter 1, argument type 2 formal parameter 2) {} |
Returns the Type method name (parameter type 1 parameters 1, parameter type 2 formal parameter 2 = default) {} |
Func function name (formal parameter 1: Parameter type 1, external parameter name parameter 2: Parameter type 2 = default), return type {} |
Calling a function (method) |
Method Name (argument 1, argument 2); |
Method Name (argument 1, argument 2); |
function name (argument 1, external parameter name: argument 2); |
Variable parameters |
Returns the Type method name (parameter type ...). Formal parameter) {} |
return type method name (params parameter type [] parameter) {} |
Func function name (formal parameter: parameter type ...) return type {} |
Outgoing parameters |
N/A, wrapped inside the object |
return type method name (ref argument type parameter) {} Returns the Type method name (out parameter type parameters) {} |
Func function name (inout parameter: argument type), return type {} |
Calling outgoing parameters |
N/A |
Actual parameters |
& Actual Parameters |
function type |
N/A, replace with single-method interface |
Action and Func series generic classes |
(parameter type 1, parameter type 2) –> return type |
Closed Package |
(parameter type parameters)-expression () –> { Multi-line statements }
|
(argument type parameter) = = Expression () = { Multi-line statements }
|
{(formal parameter: parameter type) –> return type in expression} {() –> () in Multi-line statements }
|
Enumeration |
Enum type name { enumeration value 1 (value 1), enumeration value 2 (value 2), enumeration value 3 (value 3); } |
Enum type name { enumeration value 1= value 1, enumeration value 2= value 2, enumeration value 3= Value 3 } |
Enum type name { Case enumeration value 1= value 1, enumeration value 2= value 2, enumeration value 3= value 3 } |
Structure (value type) |
N/A |
struct struct name {member} |
struct struct name {member} |
Class (Reference type) |
Class Name {member} |
Class Name {member} |
Class Name {member} |
Creating an Object instance |
New class name (argument 1, argument 2) |
New class or struct name (argument 1, argument 2) |
class or struct name (parameter name 1: Argument 1, external parameter name 2: Argument 2) |
Static members |
Static |
Static |
struct and enum static, class and Interface class |
Access level |
Public, publicly Protected, protection (in-package and subclass accessible) no modifier , default (in-package accessible) Private, privately
|
Public, publicly Protected, protection (subclass accessible) Internal, internal (accessible within Assembly) protected internal, internal protection (subclasses within the assembly are accessible) Private, privately |
Public, publicly internal, internal (accessible within the module) Private, privately |
Store Properties |
N/a,get set Prefix method naming convention |
Type property name {get; set;} = initial value; |
var attribute name: type = initial value; |
Calculated properties |
N/a,get set Prefix method naming convention |
Type property name { Get { } Set {//parameter is value } } |
var property name: type { get { } Set (parameter) {//If the parameter name is not written, the default is NewValue } } |
Indexer (subscript) |
N/A |
Return type this[parameter type argument] { Get { } Set {//parameter is value } } |
Subscript (formal parameter: parameter type) –> return type { get { } set {//parameter is NewValue } } |
Constructors |
Class name (argument type parameter) {} |
Class name (argument type parameter) {} |
Init (formal parameter: parameter type) {} |
Self instance |
This |
This |
Self |
Calling other constructors |
Class name () { This (actual parameter); } |
Class name (): this (argument) { } |
Init () { Self.init (external parameter name: actual parameter); } |
Inherited |
Class derived class extends base class {member} |
Class Derived classes: base class {member} |
Class Derived classes: base class {member} |
Call the base class constructor |
Derived class name (parameter type parameter) { Super (parameter); } |
Derived class name (parameter type parameter): Base (parameter) { } |
Init (parameter: parameter type) { Super.init (external parameter name: parameter); } |
Virtual functions |
Can be overridden by default and cannot overwrite the final |
Mark Virtual to cover |
Default can be overridden, non-overriding the superscript @final |
Sealing class |
Final |
Sealed |
@final |
Overwrite (override) |
Non-modified, can add @override |
Override |
Override |
Call the base class method |
Super. Method (); |
Base. Method (); |
Super. Method (); |
Type check |
Base class instance instanceof derived type |
Base class instance is derived type |
Base class instance is derived type |
Down transformation |
Base class instance (derived type)
|
Base class instance (derived type) Base class instance as derived type |
Base class instance as derived type Base class instance as? Derived types |
Interface |
Interface |
Interface |
Protocol |
Implementing interfaces |
Class Implement interface {member} |
Class: interface {member} |
Class: interface {member} |
Abstract class |
Abstract |
Abstract |
N/A |
Extended |
Default methods for interfaces |
Extension methods |
Extension |
Name space |
Package |
Namespace |
by module |