Type Inference (Also known as Implicit Type, Type Deduction, Placeholder Type Specifier)
There is also a Generic Functions Sections and a Generic Class Section
- C
- C++
- C#
- Java
- Rust
- Go
- Javascript
- Typescript
- Python
// ------------------------------------
// Variables
// ------------------------------------
// Not Available
// ------------------------------------
// Return Value of Functions
// ------------------------------------
// Not Available
// ------------------------------------
// Variables
// ------------------------------------
// Since C++11
auto variable = 12.5;
auto variable{4};
auto myVector{ 9, 7, 5, 3, 1 };
auto my_multi_array {{{1,2,3},{4,5,6},{7,8,9}}};
// Example without "auto":
std::array<std::array<std::int32_t, 3>, 3> my_multi_array {{{1,2,3},{4,5,6},{7,8,9}}};
auto myClassInstance = /* etc */;
// You can also use auto inside range for. Check Control Flow > Loop Section
// ------------------------------------
// Return Value of Functions
// ------------------------------------
// Since C++11
// Example without "auto":
std::array<std::array<std::int32_t, 3>, 3> my_multi_array_function()
{
// ...
}
// Using "auto":
auto my_multi_array_function()
{
// ...
}
// ------------------------------------
// Variables
// ------------------------------------
// Using var - object property and methods on compile time
var variable = 12.4;
var variable = 4;
var variable = "string";
var myClassInstance = /* etc */;
// Using dynamic - object property and methods on run time
dynamic variable = 12.4;
dynamic variable = 4;
dynamic variable = "string";
dynamic myClassInstance = /* etc */;
// ------------------------------------
// Return Value of Functions
// ------------------------------------
// Using var
// Not Available
// Using dynamic
dynamic MyMethod()
{
// ...
}
More Info:
// ------------------------------------
// Variables
// ------------------------------------
// Since Java 10
var variable = 12.4;
var variable = 4;
var variable = "string";
var myMap = new HashMap<String, List<String>();
// Also possible:
Map<String, List<String>> myMap = new HashMap<String, List<String>>(); // Full
Map<String, List<String>> myMap = new HashMap<>(); // Short
// ------------------------------------
// Return Value of Functions
// ------------------------------------
// Not Available
// Rust infers local variable types from initialization and usage.
let variable_name = 10; // i32 by default
let variable_name = 10.5; // f64 by default
let variable_name = "text"; // &str
// Explicit type annotation is still available.
let variable_name: u64 = 10;
// Turbofish can guide generic inference.
let numbers = Vec::<i32>::new();
// Go infers types with short variable declarations and var initialization.
variableName := 10
variableName := 10.5
variableName := "text"
var variableName = 10
var variableName = "text"
// Explicit type declaration is still available.
var variableName int64 = 10
// Unnecessary. Does not have types
// ------------------------------------
// Variables
// ------------------------------------
// Since TypeScript 3.0
// unknown
let variable: unknown = 12.4;
let variable: unknown = 4;
let variable: unknown = "string"
// any
// Don't use any as a type unless you are in the process of migrating a
// JavaScript project to TypeScript.
let variable: any = 12.4;
let variable: any = 4;
let variable: any = "string"
// unknown is the type-safe counterpart of any.
// Anything is assignable to unknown, but unknown isn't assignable to anything but
// itself and any without a type assertion or a control flow based narrowing.
// Likewise, no operations are permitted on an unknown without first asserting or
// narrowing to a more specific type.
// ------------------------------------
// Return Value of Functions
// ------------------------------------
// Just a normal function without return type annotation or with ": unknown"
More Info:
# Unnecessary. Does not have types
# But if the project use Type Hints Annotations (PEP 484 / Python 3.6+)
# You can specify "Any"
variable_name: Any = 10
More Info: