Tutorial by Examples: def

This annotation ensures that only the valid integer constants that you expect are used. The following example illustrates the steps to create an annotation: import android.support.annotation.IntDef; public abstract class Car { //Define the list of accepted constants @IntDef({MICROCA...
Using alarm, user can schedule SIGALARM signal to be raised after specified interval. In case user did not blocked, ignored or specified explicit signal handler for this signal, the default action for this signal will be performed on arrival. Per specification default action for SIGALARM is to termi...
If a class, enum, inline function, template, or member of a template has external linkage and is defined in multiple translation units, all definitions must be identical or the behavior is undefined according to the One Definition Rule (ODR). foo.h: class Foo { public: double x; private...
XSD schema (schema.xsd) The following xml schema (xsd) defines a list of users with attributes name and reputation. <?xml version="1.0"?> <xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://www...
An object in PHP contains variables and functions. Objects typically belong to a class, which defines the variables and functions that all objects of this class will contain. The syntax to define a class is: class Shape { public $sides = 0; public function description() { ...
While a simple mock returns null (or defaults for primitives) to every call, it is possible to change that behaviour. Dependency mock = Mockito.mock(Dependency.class, new Answer() { @Override public Object answer(InvocationOnMock invocationOnMock) throws Throwable { ...
module.exports.routes = { 'GET /foo': 'FooController.index', 'GET /foo/new': 'FooController.new', 'POST /foo/create': 'FooController.create', 'GET /foo/:id/edit': 'FooController.edit', 'PUT /foo/:id/update': 'FooController.update', 'GET /foo/:id': 'FooController.show', ...
module.exports.routes = { // This function will be executed for all http verbs on all urls 'all /*', function (req, res, next) { // Expose the function `fooBar` to all views (via the locals object) res.locals.fooBar = function (arg1) { return 'foobar' + arg1; }; }, };...
Structures in Rust are defined using the struct keyword. The most common form of structure consists of a set of named fields: struct Foo { my_bool: bool, my_num: isize, my_string: String, } The above declares a struct with three fields: my_bool, my_num, and my_string, of the type...
VB.NET offers default Form instances. The developer does not need to create the instance as it is created behind the scenes. However, it is not preferable to use the default instance all but the simplest programs. Public Class Form1 Public Sub Foo() MessageBox.Show("Bar") ...
The UMD (Universal Module Definition) pattern is used when our module needs to be imported by a number of different module loaders (e.g. AMD, CommonJS). The pattern itself consists of two parts: An IIFE (Immediately-Invoked Function Expression) that checks for the module loader that is being i...
AMD is a module definition system that attempts to address some of the common issues with other systems like CommonJS and anonymous closures. AMD addresses these issues by: Registering the factory function by calling define(), instead of immediately executing it Passing dependencies as an array...
User-defined functionals Users can create their own functionals to varying degrees of complexity. The following examples are from Functionals by Hadley Wickham: randomise <- function(f) f(runif(1e3)) lapply2 <- function(x, f, ...) { out <- vector("list", length(x...
var syntaxTree = CSharpSyntaxTree.ParseText( @"using System; using System.Collections; using System.Linq; using System.Text; namespace HelloWorldApplication { class Program { static void Main(string[] args) { Console.WriteLine(""Hello World""); } } }"); ...
I won't explain what Any and FirstOrDefault does because there are already two good example about them. See Any and First, FirstOrDefault, Last, LastOrDefault, Single, and SingleOrDefault for more information. A pattern I often see in code which should be avoided is if (myEnumerable.Any(t=>t.Fo...
In order to play a sound using the SoundEffect type, create a variable to hold the loaded sound. Typically this would be an instance variable in the Game class: private SoundEffect mySound; Then, in the LoadContent() method of the Game class: protected override void LoadContent() { // l...
It is easy to get confused in the C preprocessor, and treat it as part of C itself, but that is a mistake because the preprocessor is just a text substitution mechanism. For example, if you write /* WRONG */ #define MAX 100; int arr[MAX]; the code expands to int arr[100;]; which is a synta...
Obfuscation is often considered as a magic solution for code protection, by making your code harder to understand if it ever gets de-compiled by hackers. But if you're thinking that removing the Log.x(..) actually removes the information the hackers need, you'll have a nasty surprise. Removing al...
Compiler definitions run platform specific code. Using them you can make small differences between various platforms. Trigger Game Center achievements on apple devices and google play achievements on Android devices. Change the icons in menus (windows logo in windows, Linux penguin in Linux). P...
defaultProps allows you to set default prop values for your component. In the below example if you do not pass the name props, it will display John otherwise it will display the passed value class Example extends Component { render() { return ( <View> <Text>{this...

Page 14 of 27