Making an object that can be various types?
I have a byte[] and a short[] used for the same thing.
I want to switch from using the byte[] and short[] based on the maximum value needed, which changes occasionally.
My idea is to have an Object that is swapped between referencing the byte[] or the short[] as needed.
The part I can't figure out is casting the Object to the array type its referencing. I tried this to alter the contents of the array the object is referencing:
but it just says "the result of getClass() is unused" (aka it isnt trying to cast the Object with the result like i want it to)
13 Replies
ā
This post has been reserved for your question.
Hey @špothicon! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Why aren't you always using a
short[]
?
but no you can't cast like that
what you could do in principle is create wrapper classes for each type of array with a common (sealed) interface but I don't see much of a point in that tbhmemory usage
this is for chunks of data
with palette compression
so if the palette only has 1 or 2 values i can use an array of booleans to reference that palette
if it has 2-127 values i can use an array of bytes
then shorts for values above that
but it just says "the result of getClass() is unused" (aka it isnt trying to cast the Object with the result like i want it to)
is this an error
or a warning
warning
o
it also says this
if i hover over the red part
you could ig use an if statement
to know when to swap
yeah i can i just wanted something cleaner and less annoying to make
plus it would be faster to not have to use those if statements
one if statement doesnt sound too bad tbh
so yea try that
yeah that reduced memory usage from 1.54gb to 1.03gb
worth
and the savings from adding the boolean array might be even bigger
Post Closed
This post has been closed by <@465515365108154380>.