I code in c++ ever from the start but now have been working on project related to Network Administration on Java. Here a[i].addresses returns a NetworkInterfaceAddress[] (i.e., an array). But when I try to copy like this, it gives an error.
NetworkInterface[] a;
a=JpcapCaptor.getDeviceList();
NetworkInterfaceAddress[] b=new NetworkInterfaceAddress[a.length];
int i=-1;
while(++i<a.length)
b[i]=a[i].addresses;
This gives an error:
incompatible types: NetworkInterfaceAddress[] cannot be converted to NetworkInterfaceAddress.
The array
bis aNetworkInterfaceAddressarray, meaning that it can storeobjectsof typeNetworkInterfaceAddress. However, as you said,a[i].addressesreturns an array ofNetworkInterfaceAddressSo,bshould be capable of storing arrays of typeNetworkInterfaceAddressinstead of objects of type NetworkInterfaceAddress. For that, b should be an array of arrays or a jagged array. Change b's definition toThen, while adding
a[i].addressesin the array, assign the length of the current array inside b, that has to holda[i].addresses, toa[i].length.