What's up with this? Why does Visual Basic allow a primative types to be converted to Objects? I don't understand why this is allowed. Has it always been allowed in VB? For instance the first two code blocks would be illegal in Java. First being primative to refrence type Second being refrence to primative. But the third would be allowed.
Code:public class X{ public static void main(String[] args){ int i = 7; Test(i); } public static void Test(Object i){ System.out.println(" The value of i is " + i); } }AllowedCode:public class Y{ public static void main(String[] args){ Integer i = new Integer(7); Test(i); } public static void Test(int i){ System.out.println(" The value of i is " + i); } }
Now Visual Basic....Code:public class Z{ public static void main(String[] args){ Integer i = new Integer(7); Test(i); } public static void Test(Object i){ System.out.println(" The value of i is " + i); } }
Code:Module Module1 Public Function Add(x as Object, y as Object) Console.WrintLine(x,y) End Function Public Sub Main() Dim x as Integer = 2 Dim y as Integer = 3 Add(x,y) End Sub End Module





Reply With Quote