Results 1 to 7 of 7

Thread: Why does Visual Basic allow a primative types to be converted to Objects?

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Angry Why does Visual Basic allow a primative types to be converted to Objects?

    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);
      }
    }
    Code:
    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);
      }
    }
    Allowed
    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);
      }
    }
    Now Visual Basic....
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width