dovgqc2648 2015-02-16 13:18
浏览 18
已采纳

实例化数组中的类型

How can I instance an array with a given type?

I get the type this way:

type := reflect.ValueOf(obj)

But I don't know how to get an instance of an array with this type

  • 写回答

1条回答 默认 最新

  • duanke9540 2015-02-16 13:25
    关注

    Use reflect.MakeSlice for that:

    type := reflect.ValueOf(obj)
    reflectSlice := reflect.MakeSlice(type, sliceLength, sliceCapacity)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?