Asked  7 Months ago    Answers:  5   Viewed   33 times

Why is 08 considered an out of range int but 07 and below are not?



In Java and several other languages, an integer literal beginning with 0 is interpreted as an octal (base 8) quantity.

For single-digit numbers (other than 08 and 09, which are not allowed), the result is the same, so you might not notice that they are being interpreted as octal. However, if you write numbers with more than one significant digit you might be confused by the result.

For example:

010 ==  8
024 == 20

Since octal literals are usually not what you want, you should always take care to never begin an integer literal with 0, unless of course you are actually trying to write zero by itself.

Tuesday, June 1, 2021
answered 7 Months ago

**Similar example <label for=...>

Property and attribute aren't always 1:1. An often encountered example is the label tag

<label for="someId">

In Angular

<label [for]="someId"> 

fails with the same error and you'd need to bind like

<label attr.for="{{someId}}">


<label [attr.for]="someId">


<label [htmlFor]="someId">

would also work because in this case htmlFor is the property that is reflected to the DOM for attribute. See also for the htmlFor property (in the Properties section)

See also What is the difference between attribute and property?

colSpan the actual property name

According to colSpan is the property that is reflected to the colspan attribute therefore (uppercase S)

<td [colSpan]="1 + 1">Column</td>

See also

works just fine.

Why does Angular bind to properties by default

Angular binds to the property by default for performance reasons. Binding to an attribute is expensive because attributes are reflected in the DOM and a change in the DOM can causes reevaluation of CSS styles that might match after the change, while properties are just a value in a JavaScript object that changed.
With attr. you opt in explicitely to the expensive behavior.

Wednesday, July 28, 2021
answered 4 Months ago

why do I have to bind the push method to apply?

It's the other way round: You have to bind the apply method to the Array push function - you can bind it to other functions as well! Otherwise apply doesn't know which method to apply with the arguments.

Function.prototype.apply.bind(Array.prototype.push); does call the bind function on the apply function with push as the argument, the argument on which apply is then bound. The resulting function pushAll will, when called, invoke apply on the push function, and pass it's argument (the array and the arguments array) to it.

Shouldn't Array.prototype.push.apply already be bound to apply?

Nope. JavaScript is designed to bind the context at the call of a function, not already when it's being referred to as a property - there is no implicit binding on property access. Otherwise Array.prototype.push would already be bound to Array.prototype, before you could call any Function methods like bind/apply on it and try to use it with a different context.

Why does calling it under a different name result in calling it on an unbound context?

It's not so much different name, but different style. (Unbound) Functions do get their this value set to the object when they are called as a method on it, i.e. when the reference to the called function is a property access: destination.push().

This allows for great flexibility, you can "borrow" functions from an object and call them on other objects, still being the same (unbound) function. This is rather impossible in languages where function objects are no first-class objects.

If functions (even though they were meant to be methods) are called as plain functions (pushAll()), their this value will be undefined (unless in sloppy mode). Read more on the this keyword at MDN.

Saturday, August 14, 2021
answered 4 Months ago

the source of my solution.

the fiddle demo.

the code for interpolating arrays,

function interpolateArray(data, fitCount) {

    var linearInterpolate = function (before, after, atPoint) {
        return before + (after - before) * atPoint;

    var newData = new Array();
    var springFactor = new Number((data.length - 1) / (fitCount - 1));
    newData[0] = data[0]; // for new allocation
    for ( var i = 1; i < fitCount - 1; i++) {
        var tmp = i * springFactor;
        var before = new Number(Math.floor(tmp)).toFixed();
        var after = new Number(Math.ceil(tmp)).toFixed();
        var atPoint = tmp - before;
        newData[i] = linearInterpolate(data[before], data[after], atPoint);
    newData[fitCount - 1] = data[data.length - 1]; // for new allocation
    return newData;

example of using it:

var originalArry = [1,5,3];
var newArry = interpolateArray([1,5,3],5);
Friday, October 15, 2021
answered 2 Months ago

If really all you have is an image and you want tooltips over it - here is a 30 second description.

  • Subclass JPanel
  • override paint() method to draw image
  • Define some number of Shape objects (polygons, rects, etc...) as your "buildings" along with a text tooltip string
  • override getTooltip in JPanel subclass. On each call iterate over your Shape objects, testing if the point is inside shape (shape has a method for this). return tooltip appropriate for Shape, or null if your mouse isn't over shape
  • if you want rollover effects, register MouseMotionListener and use it to find the "hover" shape. Call repaint() and render your "hover" in some special way.
  • boom! you're done

HINT: You will need to register your JPanel with TooltipManager most likely.

Sunday, October 17, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :