Tutorial by Examples: class

<?php // Setting parameters $time = time(); $values = [7, $time, $time]; // Prints "At 3:50:31 PM on Apr 19, 2015, there was a disturbance on planet 7." $pattern = "At {1, time} on {1, date}, there was a disturbance on planet {0, number}."; $formatter = new Messa...
import com.ibm.icu.text.MessageFormat import java.util.Locale import scala.collection.JavaConverters._ // Outputs "A common message for all options. Selected: (other)" val formatted = new MessageFormat( "{messageCount, plural, one {{aMessage} (one)} other {{aMessage} (othe...
Given the following multi-release Jar: jar root - demo - SampleClass.class - META-INF - versions - 9 - demo - SampleClass.class The following class prints the URL of the SampleClass: package demo; import java.net.URL; public class Main...
The following prints the current caller class. Note that in this case, the StackWalker needs to be created with the option RETAIN_CLASS_REFERENCE, so that Class instances are retained in the StackFrame objects. Otherwise an exception would occur. public class StackWalkerExample { public stat...
When creating a std::unique_lock, there are three different locking strategies to choose from: std::try_to_lock, std::defer_lock and std::adopt_lock std::try_to_lock allows for trying a lock without blocking: { std::atomic_int temp {0}; std::mutex _mutex; std::thread t( [&...
The List interface is implemented by different classes. Each of them has its own way for implementing it with different strategies and providing different pros and cons. Classes implementing List These are all of the public classes in Java SE 8 that implement the java.util.List interface: Abs...
class Person { constructor(firstname, lastname) { this._firstname = firstname; this._lastname = lastname; } get firstname() { return this._firstname; } set firstname(name) { this._firstname = name; } get lastname() { return this._lastname; } ...
std::async: performs an asynchronous operation. std::future: provides access to the result of an asynchronous operation. std::promise: packages the result of an asynchronous operation. std::packaged_task: bundles a function and the associated promise for its return type.
As a workaround, you may use the wildfly-specific VFS api and write your own ResourceAcessor implementation, such as this one below. public class WildflyVFSClassLoaderResourceAccessor extends AbstractResourceAccessor { private ClassLoader classLoader; public WildflyVFSClassLoaderResou...
Java Singleton Pattern To implement Singleton pattern, we have different approaches but all of them have following common concepts. Private constructor to restrict instantiation of the class from other classes. Private static variable of the same class that is the only instance of the class. P...
Override Pagination Style: Every available pagination style can be overridden by creating a new class that inherits from one of the available styles and then alters its parameters: class MyPagination(PageNumberPagination): page_size = 20 page_size_query_param = 'page_size' max_page...
// src/AppBundle/Controller/HelloWorldController.php namespace AppBundle\Controller; use Symfony\Component\HttpFoundation\Response; class HelloWorldController { public function helloWorldAction() { return new Response( '<html><body>Hello World!<...
I am assuming that you have aware about the some syntax of Kotlin and how to use, just add RecyclerView in activity_main.xml file and set with adapter class. class MainActivity : AppCompatActivity(){ lateinit var mRecyclerView : RecyclerView val mAdapter : RecyclerAdapter = ...
class Simple { } class Test { void printName(Object obj){ Class c = obj.getClass(); System.out.println(c.getName()); } public static void main(String args[]){ Simple s = new Simple(); Test t = new Test(); ...
public class localInner1{ private int data=30;//instance variable void display(){ class Local{ void msg(){System.out.println(data);} } Local l=new Local(); l.msg(); } public static void main(String args[]){ localInner1 obj=new localInner1(); obj.di...
trait Show[T] { def show(t: T): String } object Show extends ProductTypeClassCompanion[Show] { def apply[T](implicit T: Show[T]) = T def from[T](f: T => String): Show[T] = new Show[T] { def show(t: T): String = f(t) } implicit val string = from[String](_.reverse) ...
An inner class which is visible to any outside class can be created from this class as well. The inner class depends on the outside class and requires a reference to an instance of it. To create an instance of the inner class, the new operator only needs to be called on an instance of the outer cla...
Most Singleton examples use MonoBehaviour as the base class. The main disadvantage is that this Singleton class only lives during run time. This has some drawbacks: There is no way of directly editing the singleton fields other than changing the code. No way to store a reference to other assets...
The following rules define a simple strategy for creating immutable objects. Don't provide "setter" methods - methods that modify fields or objects referred to by fields. Make all fields final and private. Don't allow subclasses to override methods. The simplest way to do this is to d...
interface Foo { fun example() } class Bar { fun example() { println("Hello, world!") } } class Baz(b : Bar) : Foo by b Baz(Bar()).example() The example prints Hello, world!

Page 26 of 28