Tutorial by Examples: e

Categories provide the ability to add some extra functionality to an object without subclassing or changing the actual object. For example we want to set some custom fonts. Let's create a category that add functionality to UIFont class. Open your XCode project, click on File -> New -> File a...
Def: Final Keyword prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended Final Method class BaseClass { public function test() { echo "BaseClass::test() called\n"; } ...
The @ sign binds a variable to a name during a pattern match. The bound variable can either be the entire matched object or part of the matched object: sealed trait Shape case class Rectangle(height: Int, width: Int) extends Shape case class Circle(radius: Int) extends Shape case object Point ex...
Pattern matching can also be used to check the type of an instance, rather than using isInstanceOf[B]: val anyRef: AnyRef = "" anyRef match { case _: Number => "It is a number" case _: String => "I...
The [ and [[ operators are primitive functions that are generic. This means that any object in R (specifically isTRUE(is.object(x)) --i.e. has an explicit "class" attribute) can have its own specified behaviour when subsetted; i.e. has its own methods for [ and/or [[. For example, this is...
This operator checks whether the object is of a particular class/interface type. instanceof operator is written as: ( Object reference variable ) instanceof (class/interface type) Example: public class Test { public static void main(String args[]){ String name = "Buyya";...
The left hand operand for these operators must be a either a non-final variable or an element of an array. The right hand operand must be assignment compatible with the left hand operand. This means that either the types must be the same, or the right operand type must be convertible to the left o...
Lazy evaluation means Haskell will evaluate only list items whose values are needed. The basic recursive definition is: f (0) <- 0 f (1) <- 1 f (n) <- f (n-1) + f (n-2) If evaluated directly, it will be very slow. But, imagine we have a list that records all the results, fibs ...
First, instantiate a Toast object with one of the MakeText() methods. This method takes three parameters: the application Context, the text message, and the duration for the toast. It returns a properly initialized Toast object. You can display the toast notification with Show(), as shown in the fol...
The R-Logo is a multilayer raster file (red, green, blue) library(raster) r <- stack("C:/Program Files/R/R-3.2.3/doc/html/logo.jpg") plot(r) The individual layers of the RasterStack object can be adressed by [[. plot(r[[1]])
Behavior Driven Development (BDD) testing style revolves around "given", "when" and "then" stages in tests. However, classical Mockito uses "when" word for "given" phase, and does not include other natural language constructions that can encompass B...
// static: is callable on a class even when no instance of the class has been created public static void MyMethod() // virtual: can be called or overridden in an inherited class public virtual void MyMethod() // internal: access is limited within the current assembly internal void MyMetho...
There is no simple way to obtain attributes from an interface, since classes does not inherit attributes from an interface. Whenever implementing an interface or overriding members in a derived class, you need to re-declare the attributes. So in the example below output would be True in all three c...
Selection sort selects the minimum element, repeatedly, until the list is empty. import Data.List (minimum, delete) ssort :: Ord t => [t] -> [t] ssort [] = [] ssort xs = let { x = minimum xs } in x : ssort (delete x xs)
with clause is used to combine matching clauses. It looks like we combine anonymous functions or handle function with multiple bodies (matching clauses). Consider the case: we create a user, insert it into DB, then create greet email and then send it to the user. Without the with clause we might ...
Query: SELECT * FROM Customers ORDER BY CustomerID LIMIT 3; Result: CustomerID CustomerName ContactName Address City PostalCode Country 1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Ge...
In this example our project name is "helloworld" which was created with stack new helloworld simple First we have to build the project with stack build and then we can run it with stack exec helloworld-exe
Circe provides compile-time derived codecs for en/decode json into case classes. A simple example looks like this: import io.circe._ import io.circe.generic.auto._ import io.circe.parser._ import io.circe.syntax._ case class User(id: Long, name: String) val user = User(1, "John Doe&qu...
The code below implements a very simple complex number type for which the underlying field is automatically promoted, following the language's type promotion rules, under application of the four basic operators (+, -, *, and /) with a member of a different field (be it another complex<T> or so...
To take a photo, first we need to declare required permissions in AndroidManifest.xml. We need two permissions: Camera - to open camera app. If attribute required is set to true you will not be able to install this app if you don't have hardware camera. WRITE_EXTERNAL_STORAGE - This permission i...

Page 417 of 1191