#development

1 messages · Page 1963 of 1

split hazel
#

comes with less overhead bro

wheat mesa
#

No

split hazel
#

c++ is a fat cunt compared to c

lyric mountain
#

What matters is the coder, not the language

split hazel
#

ive seen c++ and c code alike

wheat mesa
#

Java is generally slower due to the large use of the heap rather than stack

split hazel
#

not in this case

wheat mesa
#

Everything is allocated on the heap except primitives iirc

split hazel
#

im trying to do something that i cant do because c++ will not allow me

wheat mesa
#

(Pretty much)

lyric mountain
#

JVM deals with it natively, so the only difference is where the code is ran

#

You won't get better performance just because a language is lower level

wheat mesa
#

Java is partially interpreted is it not?

lyric mountain
#

Java is black magic

modest maple
split hazel
#

and i cant even use inline assembly because A that uses a flavour of assembly i greatly dislike and B C++ does not care about preserving your assembly

lyric mountain
#

A shitty C code will be slower than a good python code

modest maple
#

Have you possibly considered the fact that you might be the issue rather than the language?

wheat mesa
#

Yes that’s true but anybody with half a brain writing C will outperform python 99 times out of 100

split hazel
#

what are you even talking about

#

try perform a jump to another function in c++ without using a return

lyric mountain
split hazel
#

it will result in the stack not being released and objects not being freed

wheat mesa
#

Then free them 4head

#

Open the cage

#

Get the key

lyric mountain
#

Noone knows how jvm works, the ancient civilization who created it is long lost

earnest phoenix
split hazel
modest maple
valid sierra
#

I have an issue, I have made some custom bots for a server I am an admin in and it was hosted properly, it was running smoothly for 2 months now without any issues but all of a sudden, I am receiving rate-limited errors even tho the bot was working fine for the last 2 months, note, one of the 4 bots only has one function and that is creating member profiles and it is rarely used so that makes it even more weird

even my public bot that has been online for 5 months started receiving such errors, idk what's cause all of this

lyric mountain
earnest phoenix
#

kek

modest maple
#

I dont even write C and C++ in my day job but I know enough and have worked with it enough to say there is a reason why OS' arent strictly all written in C and why most are now being written in higher level C++ and Rust...

wheat mesa
#

Because people like not writing 10 billion lines of code

modest maple
#

also because in that 10 Billion lines of code, you can quite easily make a mistake

earnest phoenix
#

I am just lurking during this conversation trying to see if I gain any knawlege

solemn latch
split hazel
#

thing is

#

modern languages arent really written anymore to take into account the environment

valid sierra
earnest phoenix
wheat mesa
#

C is a great language but C++ is called C++ for a reason

#

++

sudden geyser
#

I don't care what os you're running or what version it's running: all I care about is if it supports websockets and the format I want

split hazel
#

as an example c++ prefers to store things on the stack rather than registers which in my context slows things down

modest maple
valid sierra
#

and it was working fine for the past few months so i am not sure what's different

wheat mesa
#

AmogOS

modest maple
split hazel
#

just because it can run it does not mean it can produce code with the environment in mind

modest maple
#

or more accurately, you shouldn't try to control it

wheat mesa
#

There’s probably a good reason it doesn’t store things in registers

modest maple
#

you think you know more than the 40 years worth of optimisations and development of your compiler?

wheat mesa
#

C++ isn’t a new language

split hazel
#

for example the register keyword in c++ used to hint to the c++ compiler to store something in registers as much as it can until it cannot

#

now it does nothing

modest maple
#

yes

#

because it was missused and people didn't know how to use it correctly

wheat mesa
#

Compiler (usually) knows best

modest maple
#

because ^

#

You would be amazed at what LLVM and GCC can do

split hazel
#

but in my case this is not exactly the problem

#

we've gone very off tangent

modest maple
#

you're like the over protected Mom at the doctors trying to tell the surgeon how best to fix your son's heart

wheat mesa
#

Even some of the simple optimizations that modern C/C++ compilers make now are impressive

split hazel
#

anyways lets start from scratch

#

what i was expressing first is that I would use assembly instead of c++ to write the scheduler code because the compiler does not take into account what I am trying to do - it does not know it has to preserve the contents of the registers, it does not know it has to release objects on the stack and heap which leads to a memory leak due to me throwing in inline assembly code which the compiler does not take into account

#

in other words it really is too high level for what i am trying to do

#

but if I were to sacrifice c++ i will struggle trying to implement classes I made such as maps and dynamic arrays in assembly

#

the compiler can do that in an instant

modest maple
#

writing your own assembly for this application is not a good idea

split hazel
#

you could say "use function calls" - i am actually trying to avoid them because they add unnecessary overhead

lyric mountain
#

these days one of my coworkers said js/python are better than java/c# because, according to him, "you have to write less code to do things"

sudden geyser
#

there's too much complexity in software today so he's right

lyric mountain
#

yeah, he also said delphi has bigger support for multi-platform than react

wheat mesa
#

Different uses for different languages

lyric mountain
wheat mesa
#

Lmfao what

split hazel
sudden geyser
#

wait

#

java for desktop apps?

#

you masochist

lyric mountain
#

then I pointed that both js and python don't support multithreading

#

he said "but node can handle it nowadays"

boreal iron
#

Never!

wheat mesa
#

Js and py are decent for desktop development but if you need anything to run fast (graphics beyond a rectangle) it’s 10000x better to use Java/c#/any other language

lyric mountain
wheat mesa
lyric mountain
#

hell even scratch I don't doubt

lament rock
#

webjs has a thread implementation

#

worker_threads is based on it iirc

wheat mesa
#

iirc node runs a couple threads internally but you only have access to one

#

Workers are the way to go with “multi threading”

lament rock
#

I mean. It literally is multithreading

#

just not very customizable considering they don't share the same memory space, so require cache go brrr

wheat mesa
#

I’ve never really done multithreading in js since it’s not a language really... designed for such a thing

lament rock
#

I remade LavaLink in js, so I had to use it

lyric mountain
#

multithreading with node is like releasing a bunch of boats at the same time, then trying to put them together later on

modest maple
#

Languages that arent written with concurrency in mind generally do suck to try and be concurrent / parallel with

#

well

lyric mountain
#

I mean, js was made as a web language, and it excels at it

wheat mesa
#

True

lament rock
#

server sided js is still good

wheat mesa
#

It would be cool to see a language similar to js but made with concurrency in mind

#

(Not sure if that exists)

lyric mountain
#

groovy

lament rock
#

maybe not ideal in all situations, but safety is their concern

modest maple
#

trying to work out a better way of phrasing native concurrency vs internal concurrency managed by the language

wheat mesa
#

A non jvm language thanks

lament rock
#

java shares more with ts than it does js

modest maple
lyric mountain
modest maple
#

but ultimately it was designed to be single threaded

#

So was C for that matter

lyric mountain
#

C was made to program apollo kekw

modest maple
#

hence why it is litterally hell on earth to use with threading

earnest phoenix
#

Because of ts I found java to be easier mmLol

lament rock
#

cs

modest maple
#

imo C# is the better package now

lament rock
#

exactly

lyric mountain
#

hell wtf is that syntax

lament rock
#

learning unity dev rn

modest maple
#

Dot net 6 is just taking dumps on Oracle and the JVM

lyric mountain
#

it's worse than c++

wheat mesa
#

Personally I prefer C# over Java

earnest phoenix
#

It is rather strict in typing ig

#

But it is still ass compared to java

lament rock
#

I really like strongly typed languages

wheat mesa
#

I dislike dynamic types

lyric mountain
lament rock
#

doesn't guarantee your code will run, but

modest maple
#

you mean strictly typed languages if you're talking about java?

lament rock
#

Not java fuck no

lyric mountain
#

it's like making a barbarian in d&d then trying to play as a diplomat

modest maple
wheat mesa
#

I like the feel of pure-OOP langs like C# and Java tbh

earnest phoenix
lament rock
#

I actually need to look at python

#

thanks for reminding me

wheat mesa
#

Pure OOP and statically typed

lyric mountain
#

hell yeah oop all the way

sudden geyser
#

sounds painful

modest maple
#

JS is dynamically typed
Python is strongly typed
C#, Rust, etc... are Strictly/Statically Typed

lyric mountain
#

it's easier to understand when u can "touch" the data

wheat mesa
#

There’s people that advocate for functional over OOP and vice versa, I find that a mix of the two is the way to go

#

Which is exactly what C# allows

lament rock
#

I meant statically typed. My bad

lyric mountain
modest maple
#

dont think c# really 'allows' it

#

it's stil tooth and claw OOP

wheat mesa
#

Yes but less so than Java imo

lyric mountain
#

don't remember his nick

modest maple
#

Asp only just added support for running the main file without a program class

wheat mesa
#

Personally I just prefer OOP design

#

To me it promotes structure and type safety

earnest phoenix
#

Personally i never bothered learning hte difference between Functional and OOP

wheat mesa
#

I understand the appeal of functional but it’s just what I like

earnest phoenix
#

I just code and call it a day

wheat mesa
#

Like even when I use ts all my shit is in classes and such lmao

earnest phoenix
#

I use classes as well

#

Ever since i discovered classes that is the only thing I really use

lament rock
#

Js anf Ts has mostly moved to class based

lyric mountain
#

OOP: MUTATIONS MUTATIONS MUTATIONS!!!!!

earnest phoenix
#

Ic

sudden geyser
#

not always true

wheat mesa
#

For example, C is a functional language for the most part (correct me if I’m wrong)

modest maple
#

mm generally it's pretty true

sudden geyser
#

functional programming is just about using functions for most things

#

but it's usually true

wheat mesa
#

And Rust considers itself mostly functional

earnest phoenix
#

I need to find a place to either learn java in a way I understand or just give up on learning java mmLol

modest maple
#

also functional languages, programs can basically be mathematically proven to work or fail

sudden geyser
#

rust isn't really functional

modest maple
#

not really functional

sudden geyser
#

it just throws itself in that pile since most languages support it

modest maple
#

it has functional concepts

wheat mesa
#

Yes but it’s not really OOP either

modest maple
#

but err yeah no

earnest phoenix
lyric mountain
#

you'll get it along the way

wheat mesa
#

C++ is whatever you want it to be

lyric mountain
#

that's how I did

earnest phoenix
#

Mmmm

modest maple
lyric mountain
#

started with the bare concepts, improved along the way

#

that's true for most langs tbh

wheat mesa
#

C++ is the ditto of paradigms

earnest phoenix
#

I learned go by making a bot

lament rock
#

Fuck around with the internals of a language for your first project. You'll do fine

earnest phoenix
#

Though I knew basics of go at that point

#

so it was a lot easier

lyric mountain
wheat mesa
#

For your first project with a language, modify the compiler!

#

😉

lament rock
#

shh don't tell them that

lyric mountain
#

imagine fcking with bash then suddenly sudo chmod 777 / -R

earnest phoenix
#

I dont even wanna know what that does

wheat mesa
#

rm -rf /

earnest phoenix
#

yea lets not do that one waffle

wheat mesa
#

Why not it’s so fun 😭

earnest phoenix
#

Mmm I think not

split hazel
#

its interesting to know that people prefer static typing which was a thing at first due to different types having different sizes which does not work well in a packed structure such as the stack

#

dynamic typing is supposed to be an advantage

earnest phoenix
#

So whats the diff between statically typed and the other one

split hazel
#

javascript stores variables on the heap doesnt it

sudden geyser
#

yeah but nowadays people like static typing for safety and convenience like autocompletion

split hazel
#

not sure

sudden geyser
#

but type systems tend to be terrible for information systems, like representing a user class

split hazel
#

yeah it is safe

modest maple
split hazel
#

and better documentation

wheat mesa
#

Everything has an underlying type either way

sudden geyser
#

yes, but dynamic systems don't force that type constraint

lyric mountain
wheat mesa
#

Dynamic typing is just types checked at run time

modest maple
#

you mean statically right?

wheat mesa
#

You’re still fucked if you screw up a type, it just might not crash or be as strict on it

sudden geyser
wheat mesa
#

Holy fuck my brain

#

I had to edit that twice

#

Lmfao

#

I’m just a big fan of the safety that static types provide

lament rock
#

I am a big fan of being lazy and having my editor do close to everything for me

#

i don't like to think

#

it is a disease

sudden geyser
#

think smart not hard

boreal iron
lament rock
#

Make a code that is thread safe and prints amogus on all threads of the cpu

boreal iron
#

And you just need to make sure it doesn’t code anything related to destroying humans freerealestate

lament rock
#

Make my game go brrr

wheat mesa
#

If you run a program that keeps printing random letters and numbers then it’ll eventually print out a perfect program

#

Just might take you until the heat death of the universe

lament rock
#

true

#

the monkey typewriter

wheat mesa
#

Yes

#

That’s the future of code

boreal iron
#

I mean it’s not a secret that a lot of things happened unexpectedly being a big step forward for humans

#

So who knows…

#

or backwards

wheat mesa
#

covid moment

boreal iron
#

Not much of an issue for most of the people on earth tbh

wheat mesa
#

Definitely

#

My school rn has 150 active covid cases KEKW

sudden geyser
#

you live in florida or something

wheat mesa
#

Texas

sudden geyser
#

oh even worse

wheat mesa
#

Precisely

boreal iron
#

Well except a few kids this group of people actually isn’t affected at all

wheat mesa
#

I’m waiting for our annual February winter storm that shuts the state down for a week

wheat mesa
split hazel
#

i'm high risk too

#

just not in your way

wheat mesa
#

I’m high risk of being hospitalized/dying of covid 😎

#

My immune system too busy fighting my own pancreas to fight anything else

boreal iron
#

If they would only thread people with an higher risk differently

rigid maple
#

I want to make a system that converts audio to text but it gives me the output like this;

boreal iron
#

Protecting them from the masses instead of separating anyone from anyone else

rigid maple
#

I don't know how to get "text" from it

rigid maple
wheat mesa
#

I mean if covid wasn’t such a political battle then it wouldn’t be a very big problem

split hazel
#

ah

boreal iron
#

Absolutely

split hazel
#

i never used their speech to text function

rigid maple
#

:(

boreal iron
#

Alright gotta need to work now oldEyes

earnest phoenix
#

@lyric mountain man making a discord bot in java just seems rather annoying rn

split hazel
#

the confidence 100% is a bit worrying

#

not a good thing in terms of machine learning

rigid maple
#

it may look normal now but its type is string

wheat mesa
#

Anyways nice discussing with you all, gotta drive now so cya

split hazel
#

what is a string?

rigid maple
#

when i push arraya it looks like this

split hazel
rigid maple
#

😃

#

so I can't get the "text" data

wheat mesa
split hazel
#

can you show me how you get the data from wit.ai

#

its an easy solution from what it looks like but that shouldnt be happening

wheat mesa
split hazel
#

yeah but it shouldnt be like that in the first place

rigid maple
#

this function

lyric mountain
#

just use jda

earnest phoenix
#

Mmm

rigid maple
earnest phoenix
#

But what should I make is the problem

lyric mountain
#

hmmm

#

well, start with a generic bot I'd say

earnest phoenix
#

Mmm okay

lyric mountain
#

after that try to find a niche to get into

split hazel
earnest phoenix
#

One thing I dislike about java is the documentation on a lot of stuff

split hazel
#

i found that to be quite buggy

earnest phoenix
#

It seems so ugly and confusing

split hazel
rigid maple
split hazel
#

so what value is the output

#

stirng?

rigid maple
#

yes

split hazel
#

remove console.log(json.parse(newarray))

#

thats probably whats stopping execution

#

then try again

sudden geyser
rigid maple
#

I am getting json syntax error again

earnest phoenix
split hazel
lyric mountain
earnest phoenix
#

I just find a lot of java packages documentation are just ugly and confusing

#

Oh?

#

ctrl Q?

rigid maple
lyric mountain
#

if on intelliij

#

ctrl+Q is quick documentation

sudden geyser
#

but every ide has that

earnest phoenix
#

I never knew this

rigid maple
#

JSON.parse(output)

earnest phoenix
#

:o

lyric mountain
#

ik, but I only know intellij shortcut

#

javadocs are very well formatted when using quickdocs

sudden geyser
#

example image pls

rigid maple
#

output gives me 2 objects, could this be the reason?

split hazel
#

can you log output?

#

without the parse

#

dont know what that library returns

rigid maple
split hazel
#

it seems like its already parsed

rigid maple
#

the output gives me 2 objects, could that be the reason?

rigid maple
lyric mountain
split hazel
#

thats really odd

#

it should not return two objects like that

lyric mountain
#

it accepts markdown, that's why

#

you can even embed images

sudden geyser
#

oh yeah that thing

rigid maple
#

are you using api?

split hazel
#

maybe it is the promisify function thats breaking the code

sudden geyser
#

intellij has a lot of nice support for java

#

was thinking outside of java because it's always been meh there

earnest phoenix
#

ctrl Q does nothing for me

lyric mountain
#

and gradle/maven/sbt/whatever

sudden geyser
#

gradle is annoying

#

I don't want to learn groovy

#

and figure out the differences between declaring dependencies

rigid maple
#

oh

lyric mountain
#

groovy is just java but with js strictness (or the lack of)

sudden geyser
#

and wait 3 minutes to install anything

lyric mountain
#

literally

rigid maple
#

i think i found it

earnest phoenix
#

KuuuHaKu are you sure its CTRL Q?

lyric mountain
#

click on something then ctrl+Q

#

the lib does need to have docs tho

#

if u just added it as dependency u might need to download docs

earnest phoenix
#

Mmm I added jda as a dep

lyric mountain
#

fetch docs

earnest phoenix
#

Also how do you supposed I handle sensitive info like discord token?

#

env file?

lyric mountain
#

I do it through init args

earnest phoenix
#

oh?

lyric mountain
#

u can also use env vars

#
export NAME='value'

./gradlew run
rigid maple
earnest phoenix
#

What if you arent using gradle tho

#

I use maven

split hazel
#

what was the problem

lyric mountain
#

idk how to start with maven, but concept is the same

rigid maple
#

i changed it like this

lyric mountain
#

if u use a init file all the envvars set there will be available within the runtime

#

just do System.getenv("name")

rigid maple
#

"Merhaba."

split hazel
#

oh i see

#

because the data comes in chunks

#

since audio takes a while

earnest phoenix
#

like the main file that gets ran?

rigid maple
#

yes, but it gives an error in the try part and goes to the catch part like that

lyric mountain
#

a file that calls the program

#

could be anything, I use a bash script for it

rigid maple
#

What if I write the code inside the catch block directly into try ?

lyric mountain
#

mvn dependency:resolve -Dclassifier=javadoc to load javadocs btw

#

press ctrl twice and put that in

#

or shift, I don't remember

rigid maple
#

worked

#

thanks for your help 🧡

earnest phoenix
#

couldn't I just make a env file and use it?

lyric mountain
#

export is how u do it in a bash file

#

you could do a env file too, it's up to u how u do it

#

just remember to gitignore it

earnest phoenix
#

yea

lyric mountain
#

to get the file just do File f = new File("path");

#

or var f = new File("path"); if u want

#

although I dislike var

earnest phoenix
#

Does it not pickup on the env file being there?

lyric mountain
#

only if u use a lib to auto load it

earnest phoenix
#

something like dotenv-java?

lyric mountain
#

probably

earnest phoenix
#

okie thanks

lyric mountain
#

I'd still use a bash/batch file for that

#

since they're already built-in and works just as fine

earnest phoenix
#

Mmm

#

Yea I just gotta figure out how to run the project to test with

lyric mountain
#

you can always press the green arrow next to main method

earnest phoenix
#

Dont I have to run it from the bash script ?

lyric mountain
#

you can set envvars from intellij

earnest phoenix
#

oh?

lyric mountain
#

"Run configurations" iirc

#

top right side

earnest phoenix
#

and I can just do System.getenv("TOKEN")?

lyric mountain
#

ye

earnest phoenix
#

sweet let me try that

#

The one thing throwing me off with java is the use of ;

#

so used to not really having to care

lyric mountain
#

you get used to it

earnest phoenix
#

So do you not use try/catch when handling exceptions?

#

My IDE completely just deleted the try/catch

lyric mountain
#

not all exceptions need it

#

there are 2 types of exceptions

earnest phoenix
#

Oh?

lyric mountain
#

Exception which is the father of all, NEEDS to be catched

#

and RuntimeException, which is an exception that might happen, doesn't need to be catched

earnest phoenix
#

So LoginException is what exactly?

lyric mountain
#

java doesn't allow u to catch something impossible to happen

lyric mountain
#

see the hierarchy

#

but everything extends Exception

#

loginexception is if u put an invalid token probably

earnest phoenix
#

Ic so there really is no need to catch it?

lyric mountain
#

you need to

#

u can also just throw it

#

public static void main(String[] args) throws LoginException {

#

btw, jsut write psvm and press ctrl + space

earnest phoenix
#
    public static void main(String[] args) throws LoginException {
        JDABuilder builder = JDABuilder.createDefault(System.getenv("TOKEN"));
        builder.setCompression(Compression.ZLIB);
        builder.enableCache(CacheFlag.MEMBER_OVERRIDES);
        builder.setEnabledIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES);

        builder.build();
    }

My IDE simply did throws LoginException just now

lyric mountain
#

ye

#

u don't need that btw

#
public static void main(String[] args) throws LoginException {
  JDA bot = JDABuilder.createDefault(System.getenv("TOKEN"))
      .setCompression(Compression.ZLIB)
      .enableCache(CacheFlag.MEMBER_OVERRIDES)
      .setEnabledIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES)
      .build();
}
#

it's a builder, u can just chain

earnest phoenix
#

Ah

lyric mountain
#

and afaik, u don't need to set compression

earnest phoenix
#

Thanks for that

#

Now time to figure out how to make a command handler

lyric mountain
#

there are many ways to make one, for instance u can just make an interface and extend all commands from it

#

then store command instances in a map

earnest phoenix
#

Mmm, I think I get the idea

lyric mountain
#
public interface Command {
  public void execute(JDA bot, Message message);
}
public class Ping extends Command {
  @Override
  public void execute(JDA bot, Message message) {
    message.getTextChannel().sendMessage("Ping!").queue()
  ]
}
public class Hi extends Command {
  @Override
  public void execute(JDA bot, Message message) {
    message.getTextChannel().sendMessage("Hello!").queue()
  ]
}
#

like this

proven lantern
#

is it discords fault when i get a 404 when responding to a webhook? anyone else ever see 404 errors like this? it happen twice is a row, but hasn't happen for months before

lyric mountain
#

both commands can be cast to Command due to common ancestors

proven lantern
#

and it's working fine again now

earnest phoenix
#

I am curious though where you would make this map?

#

And how would you add the commands to it

#

Unless you mean to add the commands to the command map in the command classes themselves

solemn latch
lyric mountain
proven lantern
lyric mountain
#
public class CommandHandler {
  public static final Map<String, Command> commands = Map.of(
    "ping", new Ping(),
    "hi", new Hi()
  )
}
#

something like that

#

obviously you can make it much more dynamic and allow aliases and shit

#

but that's an example

earnest phoenix
#

I don't think i have the knowledge currently to make an alias system

lyric mountain
#

yeah, go slow

earnest phoenix
#

I could possibly make that automatic tho.

earnest phoenix
#

Unless I can't loop through files and get the command names and then the command's class itself

#

Eh that is too much for now tbh I can't be bothered to figure out how to make it reccursive lookup

lyric mountain
#

if doing with a list ```java
public class CommandHandler {
private static final List<Command> commands = List.of(
new Ping(),
new Hi()
);

public Command getCommand(String name) {
return commands.stream()
.filter(cmd -> cmd.getName().equalsIgnoreCase(name))
.findFirst()
.orElse(null);
}
}

#

for aliases it'd be the same, you just need to make a containsIgnoreCase

earnest phoenix
#

Ohhh

#

A list is rather useful here

lyric mountain
#

there are all 3 types of collections

earnest phoenix
#

cause in the message listener I can lookup commands by name and run their exec method no?

lyric mountain
#

List, Map and Set

#

themselves have a shitton of specializations

#

like ConcurrentList

#

also, it's almost a must, INSTALL APACHE UTILS libs

#

at least collection and string utils

#

they are so useful

earnest phoenix
lyric mountain
#

ye

#

and overriden in each command

#

the advantage of interfaces is that u can have multiple files share a common signature

#

so u don't need to cast each command separately

earnest phoenix
#

So java classes don't work how i thought

#

How exactly would you provide a name for the command if Command interface specifies one needs to be set

lyric mountain
#
public interface Command {
  public void execute(JDA bot, Message message);

  public String getName();
}
public class Ping implements Command {
  @Override
  public String getName() {
    return "ping";
  }

  @Override
  public void execute(JDA bot, Message message) {
    message.getTextChannel().sendMessage("Ping!").queue()
  ]
}
public class Hi implements Command {
  @Override
  public String getName() {
    return "hi";
  }

  @Override
  public void execute(JDA bot, Message message) {
    message.getTextChannel().sendMessage("Hello!").queue()
  ]
}
#

there are ways you can decrease that

#

the one I like most is annotations

#
@Info(name = "ping")
public class Ping extends Command {
  @Override
  public void execute(JDA bot, Message message) {
    message.getTextChannel().sendMessage("Ping!").queue()
  ]
}
#

then just get the annotation of the class

#

but that's a more advanced concept, you'll get to it eventually

earnest phoenix
#

I see, also extending an interface isn't something you should do right? I thought you used implements

lyric mountain
#

ah true

#

mb

#

there

earnest phoenix
#

'onEvent(GenericEvent)' cannot override 'onEvent(GenericEvent)' in 'net.dv8tion.jda.api.hooks.ListenerAdapter'; overridden method is final What the heck does this mean?

#

Aren't you supposed to use @Override on methods in the class that extends ListenerAdapter

lyric mountain
#

onEvent shouldn't be overriden

#

there are more specialized events like onGuildMessageReceived

earnest phoenix
#

Mmm, so the readme on jda's github is wrong

#

I am trying to use the ready event

#

aha

lyric mountain
#

onReady

#

just type on and press ctrl space

#

all events will appear there

#

u can also press ctrl + O

earnest phoenix
#

no suggestions

#

kekw

lyric mountain
#

are u typing in the right place?

#

events are methods themselves

earnest phoenix
#

package events;

import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;

public class ReadyListener extends ListenerAdapter {

    @Override
    public void onReady(@NotNull ReadyEvent event) {
        System.out.printf("");
    }
}
lyric mountain
#

yep

#

u can have one class for all btw

#

no need to make multiple classes

earnest phoenix
#

Mm I see

#

I will do that then

lyric mountain
#

btw, what version are u using?

#

I recommend 4.4

#

5.0 is still in alpha

earnest phoenix
#

I was using alpha kekw

lyric mountain
#

lul

earnest phoenix
#

I love the handy

import commands.*
#

So I dont have to make a new import per command

lyric mountain
#

ye

#

u can enable automatic imports in intellij btw

earnest phoenix
#

So much about intellij I dont know

lyric mountain
#

it only gets better over time

#

also, try to make that bot open source

#

after 3 months, if you're still actively contributing to it you can grab a free jetbrains license

#

you get to keep it for as long as you develop

earnest phoenix
#

Yea I was planning on making it open source

#

Hopefully people who know java better than me can fix stuff I did poorly at and I can learn from it

lyric mountain
#

Don't worry abt it too much, you'll get better over time

#

Just keep ur tokens safe

earnest phoenix
#

so I noticed the orElse(null) doesn't actually let it return null if nothing is found so how can I check if getCommand returned nothing in the message event

lyric mountain
#

That's a peculiarity of grabbing a single element from a stream

#

You COULD just use .get(), but it's not advisable to do so

#

Since it'll throw an exception

earnest phoenix
#

I see

lyric mountain
#

There are more other than orElse

#

Like orThrow

earnest phoenix
#

I am just wondering how exactly to check if getCommand actually returned a result

#

cause if it didn't obv they can't execute a command

lyric mountain
#

Check for null

#

orElse(null) makes it return null if not found

#

It returns whatever is inside the parens

earnest phoenix
#
        String cmdName = event.getMessage().getContentRaw().substring(1).split(" ")[0];
        String[] args = event.getMessage().getContentRaw().substring(1).split(" ");
        Command command = CommandHandler.getCommand(cmdName);
        if(command == null) return;
        
        command.execute(event.getJDA(), event.getMessage(), args);

so something like this then?

#

Lets go!

vivid fulcrum
#

performance tip

#

split only once, store that in a variable

earnest phoenix
#

Thanks for that

proven lantern
#

Should both of these work?

discord -> interaction url endpoint -> return `{type: 5}` -> post https://discord.com/api/v9/webhooks/${application_id}/${token}/messages/@original

vs

discord -> interaction url endpoint -> post https://discord.com/api/v9/webhooks/${application_id}/${token}/messages/@original -> return `{type: 5}`
earnest phoenix
# lyric mountain Check for null

So I can be under the assumption that you can't do the equivalent of

let member = message.member || message.guild.members.cache.get('someID')

in java (talking about ||)

proven lantern
#

so i was wondering if order matters

#

can i return a deferred after i respond with a post

earnest phoenix
#
        Member member = message.getMentionedMembers().stream().findFirst()
                || message.getGuild().getMembers()
                .stream()
                .filter(mem -> mem.getId() == args[1])
                .findFirst()
                .orElse(message.getMember())

I was hoping this would work, but I am now learning java is more different then I thought.

#

I figured || worked similar

proven lantern
proven lantern
#

ternary operator can work kinda

lyric mountain
#

You can make a getOr method

earnest phoenix
#

Mmm

lyric mountain
#

I always make one

#
public static <T> T getOr(T get, T or) {
	return get == null ? get : or;
} 
sudden geyser
#

but who implements it

lyric mountain
#

I always put it into a global helper class

wheat mesa
#

should I make a bot in java kuu

#

just for fun

sudden geyser
#

ah

proven lantern
#

kotlin

wheat mesa
#

uh no fuck kotlin

proven lantern
#

or scala

lyric mountain
earnest phoenix
#

I was using kotlin before but there was a shit ton of issues I had

sudden geyser
#

kotlin is fun

proven lantern
#

or akka

sudden geyser
#

but I'd rather use java

earnest phoenix
#

One of them being how annoying it was to compile donw into a usable jar file

wheat mesa
#

I was considering making one in c# but I'd rather use java because it's easier with cross-platform compatibility in case I wanna throw it on to a vps

sudden geyser
#

you're going to be hosting it on linux regardless

#

oh wait development nvm

lyric mountain
#

You could also use groovy

#

Both java and c# can run groovy

#

Groovy is technically java with dlc

earnest phoenix
lyric mountain
wheat mesa
#

java is what I have to learn in school atm

#

might as well use it in some projects

lyric mountain
#

Ah fair then

earnest phoenix
wheat mesa
#

the main thing I hate about java is the ecosystem

#

gradle and maven both suck

lyric mountain
#

Use another one then

#

There are thousands of envs

wheat mesa
#

eh

#

those are the main two

earnest phoenix
#

maven is alright

lyric mountain
#

I like gradle

wheat mesa
#

probably a lot easier to use one of those than another with no documentation on how to use it

lyric mountain
#

It's pretty simple once u understand

earnest phoenix
#

So far I like the simplicity of using maven

wheat mesa
#

I'd rather use gradle than maven tbh

earnest phoenix
#

Idk the difference between the two

#

I just know maven is rather simple to use

lyric mountain
#

Maven is xml

#

Gradle is groovy

#

And believe it or not, gradle is lighter

earnest phoenix
lyric mountain
#

U could make it accept infinite args

earnest phoenix
#

Mmm

lyric mountain
#
public static <T> T getOr(T... opts) {
	for (T t : opts) {
		if (t != null) return t;
	} 

	return null;
} 
#

There are many ways to approach that

proven lantern
#

you could use streams to do that too

#

i think

lyric mountain
#

Ye

#

members.stream().findFirst().orElse(author);

earnest phoenix
#

I was using that I think

proven lantern
#

can orElse be chained?

lyric mountain
#

No, it returns an object

#

There's probably a way to chain after findFirst

earnest phoenix
#
        Member member = message.getMentionedMembers()
                .stream()
                .findFirst()
                .orElse(message.getGuild().getMembers()
                        .stream()
                        .filter(mem -> mem.getId() == args[1])
                        .findFirst()
                        .orElse(
                                message.getMember()
                        )
                );

Idk if this is efficient at all but I found this works

proven lantern
#

does java let you define functions as variables?

#

like the Function class

lyric mountain
#

Ye, 4 types

proven lantern
#

i think

lyric mountain
#

Consumer, Function, Runnable and Callable

#

Consumer and Function have Bi and Tri versions

#

And as anything else, u can make ur own

#

Never tried with var tho

sudden geyser
#

it should work

#

given they allow variables with multiple types when using var

#

with that lambda -> stuff

lyric mountain
#

Var is just a right-side type definition btw

#

It's not like js var

earnest phoenix
#
        Member member = message.getMentionedMembers()
                .stream()
                .findFirst()
                .orElse(message.getGuild().getMembers()
                        .stream()
                        .filter(mem -> mem.getId() == args[1])
                        .findFirst()
                        .orElse(
                                message.getGuild().getMembers()
                                        .stream()
                                        .filter(mem -> mem.getUser().getName() == args[0])
                                        .findFirst()
                                        .orElse(message.getMember())
                        )
                );

Something about this just seems inefficient

#

But idk

sudden geyser
#

it's just type inference made simple

lyric mountain
#

You could do this:

proven lantern
#

nesting is a code smell

earnest phoenix
#

im new to java gib break :c

proven lantern
#

it's good that you noticed it looks inefficient

#

nesting like that should set off alarm bells

earnest phoenix
#

I know typically nesting is never good

lyric mountain
#
List<Member> mbs;

if (members.isEmpty()) {
	mbs = message.getGuild().getMembers().stream()
		.filter(mb -> mb.getId().equals(args[0]))
		.toList();
} else {
	mbs = members;
} 

Member member = mbs.get(0);
earnest phoenix
#

But I don't know any other way as of right now to make this more efficient

lyric mountain
#

Members would be mentioned members

earnest phoenix
#

I see

#

But how does that help this situation wouldn't I still need to use streams?

#

I'd end up doing what I was doing before

lyric mountain
#

Not at all, you get a member at the last line

#

Ah wait, yeah you'd need to filter it

earnest phoenix
#

Mmm, but I don't want to only get by mention

#

I want to get by ID or name as well

#

and if no mention, name or id is provided it would use the member who initiated the command

lyric mountain
#

There

#

Fixed it

#

If noone is mentioned, it'll check by id

earnest phoenix
#

Yea thats cool, but again I don't only wanna check by id

#

I'd end up needing to nest again wouldn't i?

lyric mountain
#

No prob, just add a OR conditional there

proven lantern
#

do you think java will ever allow if/else statements be assigned to a variable like scala does?

lyric mountain
#

Like?

sudden geyser
#

?:?

#

personally I doubt it

#

but would like to see it

lyric mountain
#

Elvis is in groovy

proven lantern
#
String x = if(true) {
  "foo";
} else if {
  "mmmkay"
} else {
  "bar";
}```
sudden geyser
#

The only language I've seen to really get it right are lisps

#

where everything is an expression

lyric mountain
#

That's just a ternary

white anvil
#

rust does this too

lyric mountain
#

U can do that with switch btw

white anvil
#

extremely convenient

sudden geyser
#

yeah now imagine if you could do that with any construct

#

could build a lot of cool things

white anvil
#

rust can

#

everything in rust is an expression

sudden geyser
#

it can only do it with a few constructs

white anvil
#

you can do it with anything because blocks can be assigned to variables

proven lantern
#

i need to learn rust

white anvil
#

let foo = { return "bar" };

sudden geyser
#

that's just a scope

lyric mountain
#
String val = switch (type) {
	case "a" -> "Hello";
	case "b" -> "funny";
	case "c" -> "big";
	case "d" -> "world!";
};
sudden geyser
#

you can do that with any language as well

white anvil
#

not all languages allow you to return from a scope into a variable

sudden geyser
#

most (all?) do

#

like javascript

white anvil
#

does it?

proven lantern
#

that's invalid syntax

sudden geyser
#

oh yeah it doesn't

#

since it treats it like an object

earnest phoenix
lyric mountain
#

Just plain OR

#

Filter works just like in js

earnest phoenix
#

wdym just plain OR

#

if you mean what I think i've tried and it errors

lyric mountain
#

this || or || that

#

For example, both id and name are strings

#

U could do

proven lantern
earnest phoenix
#

Ah wait

#

you mean do it inside the filter

#

gotcha

white anvil
#

that’s not assigning the return value of a block to a variable though

lyric mountain
#
List<Member> mbs;

if (members.isEmpty()) {
	mbs = message.getGuild().getMembers().stream()
		.filter(mb -> mb.getId().equals(args[0]) || mb.getName().equals(args[0]))
		.toList();
} else {
	mbs = members;
} 

Member member = mbs.get(0);
sudden geyser
#

but basically the point is very expressive languages like those in the lisp family have little to no keywords

lyric mountain
#

Although for that I'd make an utility method

sudden geyser
#

so you can do things like { return 5; }

lyric mountain
#

My Helper class has more than 10k lines cuz utility

vivid fulcrum
#

wait you mean you don't paste the same methods in all of your classes

lyric mountain
#

Less words, more parens

sudden geyser
#

or

(if true
  (let [x 5]
    (+ x 5))
  (or false true))

Which basically reads, if true, return x (5) plus 5 (10), else check if false || true. In a lot of languages, if, let, +, and or are keywords

lyric mountain
#

Ah, it's actually 3k lines

#

Less than I thought

sudden geyser
#

how did you get it to 3000

white anvil
#

lisp might be expressive but it’s horrible to read

sudden geyser
#

for a helper class

white anvil
#

lol

lyric mountain
#

Utility

sudden geyser
#

lisp is actually quite beautiful once you get used to it

lyric mountain
#

My helper class is like xkcd

#

There's a method for almost all scenarios there

proven lantern
white anvil
#

love java

#

i feel like i see this in every large java project i have tried to read

lyric mountain
#

I didn't have to write that part luckily

#

Intellij manages imports for me

earnest phoenix
#

Hey haku do you know how to format a date so its like
Joined Server: 1 month ago

lyric mountain
#

Search my helper class for durationToString

#

Or u could use discord unix timestamp

#

<t:seconds:R> iirc

earnest phoenix
#

Can that be used in messages?

#

Like embeded

lyric mountain
#

Just not in titles

#

Wherever bold works so do timestamps

earnest phoenix
#

I see

#

I created my account before discord was a thing

lyric mountain
#

It's been 52 years...

earnest phoenix
#

got it fixed

lyric mountain
#

Nice

earnest phoenix
#

Say I wanted to get all roles that make them stand out from everyone else i would use a filter right?

neat ingot
#

evening gamers 🙂

lyric mountain
#

Yep

#

Filter to selectively filter-out elements

earnest phoenix
#

Mmm so I filtered out to only get the roles that hoist but how would I get the names to display them?

lyric mountain
#

Map

#

.map(Role::getName)

#

Or Role::getAsMention

#

To get as discord formatted mentions

neat ingot
#

what language is this? the :: notation reminds me of ruby.

lyric mountain
#

At the end, .collect(Collectors.joining(" "))

lyric mountain
#

That's a method reference

#

Like, the method is Role.getName()

neat ingot
#

ahh ok, not played too much with java other than basic android apps

lyric mountain
#

In a map, you can reduce .map(r -> r.getName()) to .map(Role::getName)

neat ingot
#

yea basically directly passing the function, makes sense 🙂

lyric mountain
#

After jdk 8 it improved a lot

earnest phoenix
#

that :: syntax is nice

neat ingot
#

hmm, i never really had issues with it. plenty of resources online to help guide you when lost 😄

earnest phoenix
#
                .addField("**Roles:**", member.getRoles().stream()
                        .filter(Role::isHoisted)
                        .map(Role::getAsMention)
                                .collect(Collectors.joining(", ")),
                        false
                )

Looks cleaner

neat ingot
#

but again, i only made simple apps

earnest phoenix
#

Haku has been a big help for me with java so far

#

Eventually I will have to stop asking him tho

lyric mountain
#

Always here to help a fellow coffee drinker

earnest phoenix
#

kek

#

The more I use java the more interesting it becomes

lyric mountain
#

Ah, nice

earnest phoenix
#

Yea

#

Might try and make a mc clone

lyric mountain
#

Are u using jdk 15+?

earnest phoenix
#

JDK 17

#

I didn't have a choice really linux auto installed that for me when I went to install it

lyric mountain
#

You have a ton of qol features then

#

Like multiline strings

#

And switch expressions

earnest phoenix
#

yikes one of my mouse traps just went off

lyric mountain
#

Or type check-cast

earnest phoenix
#

ah sick

#

that will probably be helpful somewhere down the line

lyric mountain
#
if (smth instanceof Command c) {
	c.doSomething();
} 
earnest phoenix
#

I was using that in the ReadyEvent before

neat ingot
#

i swear thats js 😄

earnest phoenix
#

Nah

#

some keywords just seem similar

#

So wait

lyric mountain
#

After you get used to java I really recommend peeking into groovy

#

It has ALL the vanilla features of java

warm swan
wheat mesa
#

decorators are poggy

lyric mountain
#

Such that converting a file to groovy is just changing extensions

warm swan
earnest phoenix
#

could I change this

if(command == null) return;
// to
if(command instanceof Command c) {
  c.execute(/* put the args */)
}
sudden geyser
#

have you tried kotlin before kuu

lyric mountain
sudden geyser
#

think it's buttons

warm swan
sudden geyser
#

or components

lyric mountain
warm swan
lyric mountain
earnest phoenix
#

Ah wait

#

Command is an interface

#

so instanceof wont matter here

lyric mountain
#

No problem

#

Instanceof works for both types

#

Extends and implements are brothers of the same mom

earnest phoenix
#
        String[] contents = event.getMessage().getContentRaw().substring(1).split(" ");
        Command command = CommandHandler.getCommand(contents[0]);
        if(command instanceof Command) {
            command.execute(event.getJDA(), event.getMessage(), contents);
        }
``` so I assume this then?
#

If so then that is sick

#

It negates me having to check for null myself

lyric mountain
#

In that case u could just do command != null

#

Since it's guaranteed to return something that extends Command

neat ingot
#

do you have to manually manage memory in java?

lyric mountain
#

Nope

earnest phoenix
#

Makes sense

lyric mountain
#

U can hint the gc to run tho

#

And use jvm args to customize how it works

#

ZGC is one hell of collector

neat ingot
#

why the string[] notation for a string then? seems obsolete

lyric mountain
#

Zero latency when running

lyric mountain
sudden geyser
#

means an array of strings

#

arrays in java are primitive

lyric mountain
#

java -Dname=blabla -jar myProject.jar

sudden geyser
#

most people use higher abstractions, like array lists

neat ingot
#

oooooohhhhh ok yea im dumb 😄

lyric mountain
#

String[] args will have {blabla}

earnest phoenix
#

Weird why is it returning me, the ID belongs to a bot in the guild

lyric mountain
#

Show how ur grabbing the member

#

(that didn't sound good but whatever)

neat ingot
earnest phoenix
#
        List<Member> mbs;
        List<Member> members = message.getMentionedMembers();

        if(members.isEmpty()){
            mbs = message.getGuild().getMembers().stream()
                    .filter(mb -> mb.getId().equals(args[1]) || mb.getUser().getName().equals(args[1]))
                    .toList();
        } else {
            mbs = members;
        }
        Member member = mbs.stream().findFirst().orElse(message.getMember());
lyric mountain
#

It didn't match anything then

#

It fell back to message author

earnest phoenix
#

But the bot does exist in the guild tho

#

and the ID is the bot's id

lyric mountain
#

Trim the arg then

#

Actually, how did u split it?

#

Orrr, maybe it didn't cache members

earnest phoenix
#

String[] contents = event.getMessage().getContentRaw().substring(1).split(" ");

#

that removes the prefix from the command and returns the cmdName with the arguments

earnest phoenix
lyric mountain
#

Default constructor doesn't include any intent

#

Use the normal constructor

earnest phoenix
#

I enabled the intents and the cache flag

#
.enableCache(CacheFlag.MEMBER_OVERRIDES)
                .setEnabledIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_PRESENCES)
                
lyric mountain
#

Right where u put the token

#

Second arg is intents

#

Just a sec

earnest phoenix
#

does setting intents with createDefault not work?

lyric mountain
#
EnumSet<GatewayIntent> intents = EnumSet.allOf(GatewayIntent.class);

shiroShards = DefaultShardManagerBuilder.create(ShiroInfo.getBotToken(), intents)				
	.disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS)
	.setMemberCachePolicy(m -> !m.getUser().isBot())
	.setBulkDeleteSplittingEnabled(false)
	.setEventPool(Executors.newFixedThreadPool(20), true)
	.build();
#

Damn

#

Github

#

This is how I did it

#

Shard manager, but should be the same for single JDA instance

earnest phoenix
#

I was going to ask how sharding works in jda but no point in me knowing rn

lyric mountain
#

That's how it works, everything else is the same mostly

earnest phoenix
#

Oh?

#

It auto creates shards?

lyric mountain
#

No need for broadcastEval or any weird thing

#

Just use ShardManager instead of JDA

earnest phoenix
#

I see

#

So you don't have to worry about getting guild info on a specific shard

lyric mountain
#

Nope, just grab it from shard manager

earnest phoenix
#

JDA is rather nice

lyric mountain
#

I miiiiight be doing some shameless ads, but if u want a pagination lib, there's Pagination-Utils

#

Or putils for short

earnest phoenix
#

I remember it

#

It will come in handy for me

#

Sometime soon

lyric mountain
#

Jda has jda-utilities, but for god's sake I can't understand why it's so complicated

#

That's why I made one

earnest phoenix
#

isnt jda utilities outdated?

#

at least the pagination part

lyric mountain
#

It's a mess from what I heard

#

And lacks so much documentation

earnest phoenix
#

Cosmo#2064 has logged in.17:36:29.470 JDA MainWS-ReadThread JDA ERROR One of the EventListeners had an uncaught exception java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1

#

yikes

#

I forgot if you supply whois command nothing that happens

lyric mountain
#

Hehe

#

That's something I find weird abt js

#

The lack of IndexOutOfBounds errors

earnest phoenix
#

Yea issue is if members.isEmpty() then it will try and use args[1] but if I supply nothing as well then there is no args[1]

#

I might have to check if args length is 0 before hand or smth

lyric mountain
#

Ye

#

U could always make a lenient List btw

earnest phoenix
#

Oh?

lyric mountain
#

That returns null if index doesn't exist

#
public class <T> LenientList<T> extends ArrayList<T> {
	@Override
	public T get(int index) {
		try {
			return super.get(index);
		} catch (Exception e) {
			return null;
		} 
	} 
}
#

Same for all other access methods

#

And to convert an array into list: LenientList<String> list = (LenientList<String>) List.of(args)

sudden geyser
#

you forget to check for negatives

lyric mountain
#

There

#

Or even

earnest phoenix
#

java.lang.ClassCastException: class java.util.ImmutableCollections$List12 cannot be cast to class structure.LeniantList (java.util.ImmutableCollections$List12 is in module java.base of loader 'bootstrap'; structure.LeniantList is in unnamed module of loader 'app')

#

Mmm it has an issue with
LeniantList<String> list = (LeniantList<String>) List.of(contents);

lyric mountain
#

Hm

#

Do new ArrayList<String>(List.of(args))

earnest phoenix
#

If you have the time, could you explain what that error means exactly?

lyric mountain
#

Or just make a custom constructor for LenientList

lyric mountain
#

The error comes cuz we didn't implement it

#

So it can't be cast

earnest phoenix
lyric mountain
#

That was a quick example I did, there is a lot of improvement to be done to reduce verbosity

lyric mountain
#

Cuz we extended it

earnest phoenix
#

Ah right

lyric mountain
#

Tbh

#

Just do a straight new LenientList<String>(List.of(args))

#

No cast needed

earnest phoenix
#

Can't

#

LenientList doesn't expect any args

lyric mountain
#

Since we extended ArrayList it also inherits constructor

#

No?

#

Hm

earnest phoenix
#

I already tried that aha

#

It told me it expected 0 but got 1

#

LeniantList<String> list = (LeniantList<String>) new ArrayList<String>(List.of(contents)); even when doin this same error

lyric mountain
#
public class <T> LenientList<T> extends ArrayList<T> {
	public LenientList(List<T> values) {
		super.addAll(values);
	} 

	public LenientList(T... values) {
		this(List.of(values));
	} 

	@Override
	public T get(int index) {
		try {
			return super.get(index);
		} catch (Exception e) {
			return null;
		} 
	} 
}
#

Then just new LenientList<>(args)

#

You do need to override the other methods present in ArrayList btw, to guarantee you treated all data accesses

#

Also, List<String> list = new LenientList<>(args) is valid

#

It'll keep the exception handling but allow to be passed as a generic list

#

No need to keep repeating LenientList

earnest phoenix
#

Ayo that works lets go

#
    public LenientList(List<T> values) {
        super.addAll(values);
    } 

    public LenientList(T... values) {
        this(List.of(values));
    } 

Can you explain how these two work?

#

Does the first one just allow you to give it your own list

lyric mountain
#

The top one is the actual constructor, since we extended ArrayList it contains all method of it

earnest phoenix
#

and the second let you give it stuf to make a list?

lyric mountain
#

addAll adds all the content from a list into it

earnest phoenix
#

Ah

lyric mountain
#

So when creating a new LenientList, we add all the passed values as initial content

#

The bottom constructor is an alternate constructor that calls the other one

#

This allows both a List and an array to be passed

earnest phoenix
#

Ah

#

So if no list is present it will try and use an array instead?

lyric mountain
#

Ye

earnest phoenix
#

and if that isn't it will throw a type error?

lyric mountain
#

And since we declared a varargs there, zero arguments is also valid

#

Which will result in an empty array

earnest phoenix
#

LenientList is very useful not only for just the arguments but for other things as well

#

I wish it was an actual built in java list

lyric mountain
earnest phoenix
#

Ah

lyric mountain
#

so LenientList<T> becomes LenientList<String> in this case

#

which only accepts String as values

#

this is the magic of generics

#

to have a "whatever" list, u could use LenientList<Object>

earnest phoenix
#

I see java heavily uses Generics unlike ts where you didn't really need to

lyric mountain
#

which allow all types of data

lyric mountain
#

like public <T extends Command> void addCommand(T command)

#

it'll only allow classes which extend Command

#

or implements, same thing

earnest phoenix
#

Ic

#

Also
public class <T> LenientList<T> extends ArrayList<T> {

what is the point of <T> after class cause my IDE doesn't like it being there

#

I had to remove it

lyric mountain
#

I forgot how to define generics in classes kekw

earnest phoenix
#

Ah

#

lol

lyric mountain
#

<T> defines generic extension