Tutorial by Examples: classes

A class written within a method called method local inner class. In that case the scope of the inner class is restricted within the method. A method-local inner class can be instantiated only within the method where the inner class is defined. The example of using method local inner class: public...
We can create a better mapper classes with extension methods, Suppose if i have some DTO classes like public class UserDTO { public AddressDTO Address { get; set; } } public class AddressDTO { public string Name { get; set; } } and i need to map to corresponding v...
Classes and methods are usually defined in the Smalltalk IDE. Classes A class definition looks something like this in the browser: XMLTokenizer subclass: #XMLParser instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'XML-Parser' This is actually...
C++11 All standard library containers are left in a valid but unspecified state after being moved from. For example, in the following code, v2 will contain {1, 2, 3, 4} after the move, but v1 is not guaranteed to be empty. int main() { std::vector<int> v1{1, 2, 3, 4}; std::vector&l...
Sometimes, programmers who are new to Java make the mistake of defining a class with a name that is the same as a widely used class. For example: package com.example; /** * My string utilities */ public class String { .... } Then they wonder why they get unexpected errors. For ex...
You can organize the execution of your instrumented unit tests defining a Suite. /** * Runs all unit tests. */ @RunWith(Suite.class) @Suite.SuiteClasses({MyTest1.class , MyTest2.class, MyTest3.class}) public class AndroidTestSuite {} Then in AndroidStudio you can run...
A Java entry-point class has a main method with the following signature and modifiers: public static void main(String[] args) Sidenote: because of how arrays work, it can also be (String args[]) When the java command starts the virtual machine, it loads the specified entry-point classes and...
Following example also have explanation required for understanding example within it. import java.time.Clock; import java.time.Duration; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZoneId; import java.time...
case class Meter(meters: Double) extends AnyVal case class Gram(grams: Double) extends AnyVal Value classes provide a type-safe way to encode units, even if they require a bit more characters to use them: var length = Meter(3) var weight = Gram(4) //length = weight //type mismatch; found : Gr...
Every class which overloads the operator() can be used as a function object. These classes can be written by hand (often referred to as functors) or automatically generated by the compiler by writing Lambdas from C++11 on. struct Person { std::string name; unsigned int age; }; // Func...
// Mixin to generate hidden classes @mixin generate-hidden-classes { @each $bp in map-keys($grid-breakpoints) { .hidden-#{$bp} { @include media-breakpoint-only($bp) { display: none !important; } } } } // Call to the mixin @include generate-hidden-classes(...
<ul class="list-group"> <li class="list-group-item list-group-item-success">Dapibus ac facilisis in</li> <li class="list-group-item list-group-item-info">Cras sit amet nibh libero</li> <li class="list-group-item list-group-...
We can add adaptivity to any subclass of UIView which we add on view controller in nib file. Lets take an example of adding adaptivity using size classes to a view. Add a view on view controller as: Now we need to pin this view to it's superview for fixing it's size and position using con...
What is a metaclass? In Python, everything is an object: integers, strings, lists, even functions and classes themselves are objects. And every object is an instance of a class. To check the class of an object x, one can call type(x), so: >>> type(5) <type 'int'> >>> typ...
If you've got an interface with a generic type parameter, Spring can use that to only autowire implementations that implement a type parameter you specify. Interface: public interface GenericValidator<T> { public T validate(T object); } Foo Validator Class: @Component public class...
There are many classes available in CIM and WMI which are separated into multiple namespaces. The most common (and default) namespace in Windows is root/cimv2. To find the righ class, it can useful to list all or search. List available classes You can list all available classes in the default name...
The ClassLoader needs to provide a ProtectionDomain identifying the source of the code: public class PluginClassLoader extends ClassLoader { private final ClassProvider provider; private final ProtectionDomain pd; public PluginClassLoader(ClassProvider provider) { this...
In order to achieve type safety sometimes we want to avoid the use of primitive types on our domain. For instance, imagine a Person with a name. Typically, we would encode the name as a String. However, it would not be hard to mix a String representing a Person's name with a String representing an e...
We can statically bootstrap an application by taking the plain ES5 Javascript output of the generated factory classes. Then we can use that output to bootstrap the application: import { platformBrowser } from '@angular/platform-browser'; import { AppModuleNgFactory } from './main.ngfactory'; //...
Swift does not support multiple inheritance. That is, you cannot inherit from more than one class. class Animal { ... } class Pet { ... } class Dog: Animal, Pet { ... } // This will result in a compiler error. Instead you are encouraged to use composition when creating your types. This can b...

Page 5 of 6