Answer the question
In order to leave comments, you need to log in
How to convert the given code to kotlin?
Good afternoon, I am rewriting my packages for Kotlin and ran into a problem, namely that it is impossible to assign and return to Kotlin. The code that was:
public class Packet
{
private ByteBuf buf;
protected ByteBuf buf()
{
return buf != null ? buf : (buf = Unpooled.buffer());
}
@Override
public final void fromBytes(ByteBuf buf)
{
this.buf = buf;
}
@Override
public final void toBytes(ByteBuf buf)
{
if (buf != null)
buf.writeBytes(this.buf);
}
}
class Packet
{
private var buf: ByteBuf? = null
protected fun buf(): ByteBuf
{
return buf ?: ({buf = Unpooled.buffer(); buf}()!!)
}
override fun fromBytes(buf: ByteBuf)
{
this.buf = buf
}
override fun toBytes(buf: ByteBuf?)
{
buf?.writeBytes(this.buf)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question