Compiler Designing W10L1802

Java Arrays

  • Having multiple aliases with updatable data with different type are unsound. Example,
//B < A
B [] b =new B();
A [] a = b;
a[0] = new A();
b[0].aMethodNotInA();                 //error, unsound!

Solution is to disallow subtyping using arrays, this solution is also adopted by COOL. The above code will be valid if B = A.

Java produces exception by checking at run-time, if an array is created then it checks for all of it’s assignment. If object type doesn’t match then error is raised. This adds an overhead of checking the array of objects and yes, primitive types are not classes.

Advertisements

Help to improve or comment as you wish

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s