示例#1
0
func (g *JavaToGoBoolean) Convert(obj *gojvm.Object) (err error) {
	v, err := obj.CallBool(g.env, false, "booleanValue")
	if err != nil {
		return
	}
	*g.boolPtr = v
	return
}
示例#2
0
func (j *JavaToGoIterator) Convert(obj *gojvm.Object) (err error) {
	r_value := reflect.ValueOf(j.list)

	if r_value.Type().Kind() != reflect.Ptr {
		return errors.New("JavaToGoList.Convert: dest not ptr")
	}

	r_slice := reflect.Indirect(r_value)
	if r_slice.Type().Kind() != reflect.Slice {
		return errors.New("JavaToGoList.Convert: dest ptr , does not point to slice")
	}

	for {
		hasNext, err := obj.CallBool(j.env, false, "hasNext")
		if err != nil {
			return err
		}
		if hasNext == false {
			break
		}

		next, err := obj.CallObj(j.env, false, "next", types.Class{types.JavaLangObject})
		if err != nil {
			return err
		}

		r_newElem := reflect.Indirect(reflect.New(r_slice.Type().Elem()))
		j.item.Dest(r_newElem.Addr().Interface())
		if err = j.item.Convert(next); err != nil {
			return err
		}
		if err = j.item.CleanUp(); err != nil {
			return err
		}

		r_newSlice := reflect.Append(r_slice, r_newElem)
		r_slice.Set(r_newSlice)
	}

	return
}