Can a dishwasher be hardwired instead of cord and plug connected?
Yes. Nothing in the NEC forces a dishwasher onto a cord and plug. Section 422.16(B)(2) is a permission, not a mandate, and a hardwired dishwasher has been legal for decades. What changes when you hardwire is how you satisfy the disconnecting means.
The cord and plug option
Section 422.16(B)(2) permits a built-in dishwasher to be cord and plug connected with a flexible cord identified as suitable in the installation instructions. The cord has to be 3 to 4 feet long measured from the face of the attachment plug to the plane of the rear of the appliance. The receptacle has to be located in the space occupied by the appliance or in an adjacent cabinet space, and it has to be accessible. That last part matters. A receptacle buried behind the dishwasher where you cannot reach the plug without pulling the unit is not accessible in the way the section intends. Most installers put it in the sink base.
The disconnecting means when you hardwire
Section 422.31(B) requires that for a permanently connected appliance rated over 300 volt amperes, the branch circuit switch or circuit breaker is permitted to serve as the disconnecting means where it is within sight from the appliance or is capable of being locked in the open position per 110.25. A dishwasher exceeds 300 volt amperes, so you need one of the following. Either the breaker is in sight of the dishwasher, which almost never happens in a kitchen, or the breaker has a lockout that stays in place with or without the lock installed, or you install a local switch. A lockout kit on the breaker is the cheap answer and it is what most inspectors expect to see on a hardwired unit.
GFCI is required either way
Section 210.8(D) of the 2023 NEC requires GFCI protection for the appliances listed in that subsection when they are rated 150 volts or less to ground and 60 amperes or less, single or three phase. Dishwashers are on that list. The protection has to be readily accessible, so a GFCI breaker in the panel is the usual solution. Note that 210.8(D) applies to hardwired appliances too. Hardwiring does not exempt you.
Sharing the circuit
Section 210.23(B) limits the load on a 20 ampere circuit supplying both fixed utilization equipment and other outlets. Manufacturer instructions for most dishwashers call for a dedicated circuit, and Section 110.3(B) makes those instructions enforceable. Run a dedicated 20 ampere circuit and the question does not come up.
Field takeaway
Hardwire it if you want. Add a breaker lockout or a local switch, put it on a GFCI protected dedicated 20 ampere circuit, and follow the manufacturer instructions. If you prefer the cord, use a listed dishwasher cord kit of the right length and land the receptacle in the sink base where it can be reached.