Here’s an example to show how to implement compareTo
in a decorator.
Continue reading “Decorator implementing Comparable”
Category: Programming
Abstraction vs abstract
Abstraction is very important in Java. And there’s the keyword abstract. But the use of abstract is not abstraction. It’s a common misconception that the abstract keyword is used for abstraction.
Continue reading “Abstraction vs abstract”
OOP isn’t about inheritance
Any book on OOP must explain inheritance, simply because it’s an important part of OOP in many languages. And since it’s so hard to explain and understand a large part of the book will be just about inheritance. This may lead to the false impression that OOP is just about inheritance.
Regular Expressions
I often notice that many students of programming do not understand the actual meaning of regular expressions. And I have seen online tutorials and even books that do not explain properly what regular expressions are.
Continue reading “Regular Expressions”Pass-By-Reference in Java
Java is Pass-By-Value. I list some alternatives.
Why is String immutable?
This has been answered a million times (I get a million results on google). But my answer is the most bestest!
Continue reading “Why is String immutable?”Misnomer: String.length()
The method String.length()
gives the length of the String, right? Or does it?
Functional Java Tuples
Just a prototype so far:
https://github.com/claudemartin/FunctionalJavaTuples
The generic types of the arguments are always A, B, C, etc. The result is of generic type R.
It’s my goal to have three forms:
- Method/Lambda Form: Takes n arguments
- Curried Form: Methods are chained
A -> B -> C -> ... -> R
- Uncurried Form: Takes a tuple
(A,B,C,...) -> R
The idea is to add all the basic functions of Haskell to a project that then uses javatuples.org to have a way of using tuples for functional programming in Java 8.
- curry / uncurry
- zip / unzip
- composition (“.”-operator in Haskell)
- pipes (“|>” in F#)
- partial application
fn.arity()
returns the arity of the function.- Convert Suppliers and Consumers to Functions.
There’s still a lot to do…
List of TODOs:
- Implementations of
Fn
forQuad ... Decade
- Unit-Tests (instead of FunctionalDemo.java)
- Types
Curried
andUncurried
for such forms of the methods
Contact me on github if you are interested in this project.
Generic Array Creation
Arrays of generic types are often hard to create and handle. I’ll show you how to create an array of a class with a generic parameter.
Is a Constructor a Method?
Why a constructor is not a method.
No, it’s not. In reflection both extend Executable
, but Constructor
does not extend Method
. It is a common misconception that constructors are methods and often asked about at job interviews.