code: public static Integer getHoles(Geometry g) {
          if(g == null) {
              return null;
          }
          if (g instanceof MultiPolygon) {            
              Polygon p = (Polygon) g.getGeometryN(0);
              if(p!=null){
                  return p.getNumInteriorRing();
              }            
          } else if (g instanceof Polygon) {
              return ((Polygon) g).getNumInteriorRing();
          }
          return null;
      }
docs: Return the number of holes in a Polygon or MultiPolygon
  @param g Geometry instance
  @return Number of holes or null if geometry is null