This can be a hard one, since it requires from you to be familiar with Drools. Consider the condition side of the following rules: rule "object comparison one" no-loop when $customer1 : Customer( ) $customer2 : Customer(this != $customer1) then System.out.println("Rule one – Objects are equal"); end rule "object comparison two" no-loop when $customer1 : [...]
Read Full Post »
Posted by Alexander Zagniotov in: brainteaser, drools on Aug 22nd, 2009 22:50
Consider the following case of inheritance: public class Parent { public Parent() { getValue(); } public void getValue() { } } public class Child extends Parent { private final Integer integer; public Child() { integer = new Integer(888); } @Override public void getValue() { System.out.println(integer); } } Question: What would the following program print, why? [...]
Read Full Post »
Posted by Alexander Zagniotov in: brainteaser, design patterns, java on Apr 18th, 2009 12:02
Consider the following case of inheritance: public class ExtendingHashSet<E> extends HashSet<E> { private int counter = 0; public ExtendingHashSet() { } @Override public boolean add(E e) { counter++; return super.add(e); } @Override public boolean addAll(Collection<? extends E> c) { counter += c.size(); return super.addAll(c); } public int getCounter() { return counter; } } Created instance: [...]
Read Full Post »
Posted by Alexander Zagniotov in: brainteaser, design patterns on Apr 5th, 2009 20:34
Question: The following program returns result “1″, which indicates that first Integer value is greater than the second, why? import java.util.*; public class Example { public static void main(String[] args) { System.out.println("Result: " + naturalOrder.compare(new Integer(90), new Integer(90))); } private static Comparator<Integer> naturalOrder = new Comparator<Integer>() { public int compare(Integer first, Integer second) { return [...]
Read Full Post »
Posted by Alexander Zagniotov in: brainteaser, design patterns, java on Oct 19th, 2008 00:25
When I came across the following example I did not expect the results that the program has printed hehe… Question: What does this program print? Why? import java.util.*; public class SetList { public static void main(String[] args) { Set<Integer> set = new TreeSet<Integer>(); List<Integer> list = new ArrayList<Integer>(); for (int i = -3; i < [...]
Read Full Post »
Posted by Alexander Zagniotov in: brainteaser, java on Oct 1st, 2008 13:31