java - Incompatible return type of phone number -


how should change code inside of getphonenumber work correctly, idea? should in end +38(050)123-45-67. 38 code of country, phone number 501234567, have put 0 in begin of number 10 numbers here (>0<50)

public string getphonenumber()         {            return string.format("+%d(%2$s)%3$s-%4$s-%5$s", 38,                     string.format("%010d", 501234567).substring(0, 3),                     string.format("%010d", 501234567).substring(3, 6),                     string.format("%010d", 501234567).substring(6, 8),                     string.format("%010d", 501234567).substring(8));          } 

complete code.

public class solution {     public static map<string,string> countries = new hashmap<string,string>();      public static class incomedataadapter implements customer, contact, incomedata     {         incomedata incomedata;          public incomedataadapter(incomedata incomedata)         {             countries.put("ua","ukraine");             countries.put("ru", "russia");             countries.put("ca", "canada");             this.incomedata = incomedata;         }          @override         public string getname()         {             return incomedata.getcontactlastname()+ incomedata.getcontactfirstname();         }          @override         public string getphonenumber()         {            return string.format("+%d(%2$s)%3$s-%4$s-%5$s", 38,                     string.format("%010d", 501234567).substring(0, 3),                     string.format("%010d", 501234567).substring(3, 6),                     string.format("%010d", 501234567).substring(6, 8),                     string.format("%010d", 501234567).substring(8));          }             @override         public string getcompanyname()         {             return incomedata.getcompany();         }          @override         public string getcountryname()         {             return countries.get(incomedata.getcountrycode());         }          @override         public string getcontactfirstname()         {             return "ivan";         }          public incomedata getincomedata()         {             return incomedata;         }          @override         public string getcountrycode()         {             return "ua";         }            @override         public string getcompany()         {             return "javarush ltd.";         }          @override         public string getcontactlastname()         {             return "ivanov";         }          @override         public int getcountryphonecode()         {             return 38;         }     }      public static interface incomedata {         string getcountrycode();                 string getcompany();                     string getcontactfirstname();           string getcontactlastname();             int getcountryphonecode();              void getphonenumber();               }      public static interface customer {         string getcompanyname();                 string getcountryname();            }      public static interface contact {         string getname();                        string getphonenumber();             } } 

both incomedata , contact interfaces have getphonenumber method. 1 declares return type of void while other declares return type of string.

you're trying implement both these interfaces incomedataadapter class. declaring overriden method was

@override public string getphonenumber() { 

it doesn't satisfy contract of incomedata. if declared as

@override public void getphonenumber() { 

it wouldn't satisfy contact interface. basically, can't have methods same definition (name , parameter list) different return types.

change incomedata interface declare getphonenumber method string return type.


Comments

Popular posts from this blog

My HTML document is not linking to my CSS stylesheet properly -

php array slice every 2th rule -

node.js - Sending sockets to client side, Error: Converting circular structure to JSON -