function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Taresh PandeyTaresh Pandey 

Compile time error

Hello all,
          This code having error while compiling I.e. Incompatible element type Another.Runtime for collection of Integer at line 20 column 17. Friends I'm not able to understand this error, please let me know if you can figureout this error.

Public class Another
{
    public class Runtime
    {
        Public string name;
        Public boolean Exist;
        public Integer Phone;
    }
    public List<Runtime> RuntimeList (List<Runtime> LR)
    {
        return LR;
    }
    public List<Integer> Phonenumbers (List<Integer> Phnumber)
    {
        List<integer> Allrecords = new List<integer> ();
        for(Runtime IT : Phnumber)
        {
            If(IT!=null)
            {
                Allrecords.add(IT);
            }
        }
    }
}

 
Best Answer chosen by Taresh Pandey
Abhishek BansalAbhishek Bansal
Hi Taresh,

Please change our code as mentioned below :
 
Public class Another
{
    public class Runtime
    {
        Public string name;
        Public boolean Exist;
        public Integer Phone;
    }
    public List<Runtime> RuntimeList (List<Runtime> LR)
    {
        return LR;
    }
    public List<Integer> Phonenumbers (List<Integer> Phnumber)
    {
        List<integer> Allrecords = new List<integer> ();
        for(Integer IT : Phnumber)
        {
            If(IT!=null)
            {
                Allrecords.add(IT);
            }
        }
    }
}

Phnumber is list of Integer and you are using Runtime that's why error is coming.
Hope that helps you.

Regards,
Abhishek.
 

All Answers

Abhishek BansalAbhishek Bansal
Hi Taresh,

Please change our code as mentioned below :
 
Public class Another
{
    public class Runtime
    {
        Public string name;
        Public boolean Exist;
        public Integer Phone;
    }
    public List<Runtime> RuntimeList (List<Runtime> LR)
    {
        return LR;
    }
    public List<Integer> Phonenumbers (List<Integer> Phnumber)
    {
        List<integer> Allrecords = new List<integer> ();
        for(Integer IT : Phnumber)
        {
            If(IT!=null)
            {
                Allrecords.add(IT);
            }
        }
    }
}

Phnumber is list of Integer and you are using Runtime that's why error is coming.
Hope that helps you.

Regards,
Abhishek.
 
This was selected as the best answer
Taresh PandeyTaresh Pandey
thank you Abhishek ... that issue has been resolved.