I am working in JAVA Maven project. I have one class
package com.fist.program;
import java.util.ArrayList;
import java.util.Arrays;
public class BundleVersionManagement {
public static ArrayList<String> BundleVer = new ArrayList<String>();
public static ArrayList<String> BundleName= new ArrayList<String>();
public BundleVersionManagement(){
}
public void SetBundleVersion(String BundleVersion) {
if(BundleVer.contains(BundleVersion)==false){
BundleVer.add(BundleVersion);
}
}
public void SetBundleName(String Bndnm) {
if(BundleName.contains(Bndnm)==false){
BundleName.add(Bndnm);
}
}
public void DisplayArr(){
System.out.println("common program ::: BundleVersionManagement::: bundle versions :");
System.out.println(Arrays.toString(BundleVer.toArray()));
System.out.println("common program ::: BundleVersionManagement::: bundle name :");
System.out.println(Arrays.toString(BundleName.toArray()));
}
}
Above class it's working fine. I want to use above static arraylist in another package class.
package com.first.secondProgram;
import com.fist.program.BundleVersionManagement;
public abstract class Handler<T> {
static{
BundleVersionManagement hbm = new BundleVersionManagement();
NameFromxml= hbm.BundleName;
System.out.println("common handler ::: Print array list:");
hbm.DisplayArr();
}
}
Problem is that class BundleVersionManagement add arraylist successfully as per log :
[1.123, 2.057, 3.018, 4.012, 5.018, 6.011, 7.119]
But when I print same arraylist in Hanlder class of another package, it's display blank :
common handler ::: Print array list: common util :::
BundleVersionManagement::: bundle versions : [] common util :::
BundleVersionManagement::: bundle name : []
Can you please help me how to access array list string another package.
bundleNamego with the firstbundleVersion, etc? If so this is in serious need of redesign. Also the use ofpublic staticis a red flag. Sounds like you should be using dependency injection instead.