Cannot refer to a non-final variable inside an inner class defined in a different method

Java doesn’t support true closures, even though using an anonymous class like you are using here (new TimerTask() { … }) looks like a kind of closure. edit – See the comments below – the following is not a correct explanation, as KeeperOfTheSoul points out. This is why it doesn’t work: The variables lastPrice and … Read more

Safe method to get value of nested dictionary

You could use get twice: example_dict.get(‘key1’, {}).get(‘key2’) This will return None if either key1 or key2 does not exist. Note that this could still raise an AttributeError if example_dict[‘key1’] exists but is not a dict (or a dict-like object with a get method). The try..except code you posted would raise a TypeError instead if example_dict[‘key1’] … Read more

Difference between method and function in Scala

Jim has got this pretty much covered in his blog post, but I’m posting a briefing here for reference. First, let’s see what the Scala Specification tell us. Chapter 3 (types) tell us about Function Types (3.2.9) and Method Types (3.3.1). Chapter 4 (basic declarations) speaks of Value Declaration and Definitions (4.1), Variable Declaration and … Read more

How to display all methods of an object?

You can use Object.getOwnPropertyNames() to get all properties that belong to an object, whether enumerable or not. For example: console.log(Object.getOwnPropertyNames(Math)); //-> [“E”, “LN10”, “LN2”, “LOG2E”, “LOG10E”, “PI”, …etc ] You can then use filter() to obtain only the methods: console.log(Object.getOwnPropertyNames(Math).filter(function (p) { return typeof Math[p] === ‘function’; })); //-> [“random”, “abs”, “acos”, “asin”, “atan”, “ceil”, … Read more

How to find where a method is defined at runtime?

This is really late, but here’s how you can find where a method is defined: http://gist.github.com/76951 # How to find out where a method comes from. # Learned this from Dave Thomas while teaching Advanced Ruby Studio # Makes the case for separating method definitions into # modules, especially when enhancing built-in classes. module Perpetrator … Read more

List view getListItemXmlAttributes method fails with child publication items

[Exception… “Component returned failure code: 0x80004002 (NS_NOINTERFACE) [nsIWebProgress.DOMWindow]” This means that there was no window assigned to the nsIWebProgress object. So it has nowhere to display data. nsresult: “0x80004002 (NS_NOINTERFACE)” location: “JS frame :: chrome://browser/content/tabbrowser.xml :: :: line 545” data: no] This is telling you what file is associated with that error. and what line … Read more

When is the finalize() method called in Java?

The finalize method is called when an object is about to get garbage collected. That can be at any time after it has become eligible for garbage collection. Note that it’s entirely possible that an object never gets garbage collected (and thus finalize is never called). This can happen when the object never becomes eligible … Read more